File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -124,9 +124,9 @@ export const form = () => request => {
124124export const json = ( ) => request => {
125125 if ( request . options . json ) {
126126 request . options . body = JSON . stringify ( request . options . json ) ;
127- request . options . headers . Accept = 'application/json' ;
128127 request . options . headers [ 'Content-Type' ] = 'application/json' ;
129128 }
129+ request . options . headers . Accept = 'application/json' ;
130130
131131 return response => {
132132 const contentType = response . headers . get ( 'Content-Type' ) || '' ;
Original file line number Diff line number Diff line change @@ -178,6 +178,30 @@ describe('Middleware json', done => {
178178 assert . equal ( request . options . headers [ 'Content-Type' ] , 'application/json' ) ;
179179 assert . equal ( request . options . headers . Accept , 'application/json' ) ;
180180 } ) ;
181+
182+ it ( 'should handle request without body and response.' , ( ) => {
183+ const request = {
184+ options : {
185+ headers : { } ,
186+ } ,
187+ } ;
188+
189+ const response = {
190+ headers : {
191+ get : key => {
192+ assert . equal ( key , 'Content-Type' ) ;
193+ return 'application/json' ;
194+ } ,
195+ } ,
196+ json : ( ) => Promise . resolve ( ( { key : 'value' } ) ) ,
197+ } ;
198+
199+ json ( ) ( request ) ( response ) . then ( response => {
200+ assert . equal ( response . jsonData , { key : 'value' } ) ;
201+ done ( ) ;
202+ } ) ;
203+ assert . equal ( request . options . headers . Accept , 'application/json' ) ;
204+ } ) ;
181205} ) ;
182206
183207
You can’t perform that action at this time.
0 commit comments