File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ export default class ResponseUtils {
5353 }
5454
5555 static jsonPromise ( json : MockHandler ) : Promise < ResponseData > {
56- const response : ResponseData = { body : JSON . stringify ( json ) } as ResponseData ;
56+ const response : ResponseData = { body : JSON . stringify ( json ) } ;
5757 return Promise . resolve ( response ) ;
5858 }
5959
@@ -67,14 +67,21 @@ export default class ResponseUtils {
6767
6868 static statusCode ( status : number ) : MockHandler {
6969 return ( args : HandlerArgument ) => {
70- const response : ResponseData = { status } as ResponseData ;
70+ const response : ResponseData = { status } ;
7171 return Promise . resolve ( response ) ;
7272 } ;
7373 }
7474
7575 static statusText ( statusText : string ) : MockHandler {
7676 return ( args : HandlerArgument ) => {
77- const response : ResponseData = { statusText } as ResponseData ;
77+ const response : ResponseData = { statusText } ;
78+ return Promise . resolve ( response ) ;
79+ } ;
80+ }
81+
82+ static headers ( headers : { [ key : string ] : string } ) : MockHandler {
83+ return ( args : HandlerArgument ) => {
84+ const response : ResponseData = { headers } ;
7885 return Promise . resolve ( response ) ;
7986 } ;
8087 }
Original file line number Diff line number Diff line change @@ -219,6 +219,21 @@ describe('FetchMock', () => {
219219 Promise . all ( [ first , second ] ) . then ( ( ) => done ( ) ) ;
220220 } ) ;
221221
222+ it ( 'should be able to set headers' , done => {
223+ mock . get (
224+ '/withheaders' ,
225+ ResponseUtils . combine (
226+ ResponseUtils . json ( { key : 'value' } ) ,
227+ ResponseUtils . headers ( { 'Content-Type' : 'custom/type' } )
228+ )
229+ ) ;
230+
231+ fetch ( '/withheaders' ) . then ( resp => {
232+ expect ( resp . headers . get ( 'Content-Type' ) ) . toBe ( 'custom/type' ) ;
233+ done ( ) ;
234+ } ) ;
235+ } ) ;
236+
222237 it ( 'should support lowercase httpverb' , done => {
223238 mock . post ( '/lowercase' , { key : 'BIG-CASE' } ) ;
224239
You can’t perform that action at this time.
0 commit comments