File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ class Response {
7070 */
7171 set ( key , value ) {
7272 this . responseObj . headers [ key . toLowerCase ( ) ] = value ;
73+ return this ;
7374 }
7475
7576 /**
@@ -79,6 +80,7 @@ class Response {
7980 */
8081 status ( status ) {
8182 this . responseObj . statusCode = status ;
83+ return this ;
8284 }
8385
8486 /**
@@ -88,6 +90,7 @@ class Response {
8890 */
8991 type ( type ) {
9092 this . set ( 'Content-Type' , type ) ;
93+ return this ;
9194 }
9295}
9396
Original file line number Diff line number Diff line change @@ -50,5 +50,39 @@ describe('Response object', () => {
5050 // Should work case insensitive
5151 expect ( response . get ( 'x-Header' ) ) . toBe ( 'a' ) ;
5252 } ) ;
53+
54+ it ( 'can chain status method' , ( ) => {
55+ const cb = ( err , response ) => {
56+ expect ( response . statusCode ) . toBe ( 201 ) ;
57+ } ;
58+
59+ const response = new Response ( null , cb ) ;
60+
61+ response . status ( 201 ) . end ( ) ;
62+ } ) ;
63+
64+ it ( 'can chain set method' , ( ) => {
65+ const cb = ( err , response ) => {
66+ expect ( response . headers ) . toEqual ( {
67+ 'x-header' : 'a'
68+ } ) ;
69+ } ;
70+
71+ const response = new Response ( null , cb ) ;
72+
73+ response . set ( 'x-header' , 'a' ) . end ( ) ;
74+ } ) ;
75+
76+ it ( 'can chain type method' , ( ) => {
77+ const cb = ( err , response ) => {
78+ expect ( response . headers ) . toEqual ( {
79+ 'content-type' : 'text/xml'
80+ } ) ;
81+ } ;
82+
83+ const response = new Response ( null , cb ) ;
84+
85+ response . type ( 'text/xml' ) . end ( ) ;
86+ } ) ;
5387} ) ;
5488
You can’t perform that action at this time.
0 commit comments