@@ -10,19 +10,31 @@ describe('customFetch', () => {
1010 const mockResponse = { data : 'test' } ;
1111 mockFetch . mockResolvedValueOnce ( {
1212 ok : true ,
13- headers : { get : ( ) => 'application/json' } ,
13+ headers : new Headers ( {
14+ 'content-type' : 'application/json' ,
15+ 'per-page' : '10' ,
16+ 'total' : '100' ,
17+ } ) ,
1418 json : ( ) => Promise . resolve ( mockResponse ) ,
1519 } ) ;
1620
1721 const result = await customFetch ( 'https://api.test.com' ) ;
18- expect ( result ) . toEqual ( mockResponse ) ;
22+ expect ( result ) . toEqual ( {
23+ ...mockResponse ,
24+ perPage : 10 ,
25+ total : 100 ,
26+ } ) ;
1927 } ) ;
2028
2129 it ( 'should handle object body by stringifying it' , async ( ) => {
2230 const body = { test : 'data' } ;
2331 mockFetch . mockResolvedValueOnce ( {
2432 ok : true ,
25- headers : { get : ( ) => 'application/json' } ,
33+ headers : new Headers ( {
34+ 'content-type' : 'application/json' ,
35+ 'per-page' : '10' ,
36+ 'total' : '100' ,
37+ } ) ,
2638 json : ( ) => Promise . resolve ( { } ) ,
2739 } ) ;
2840
@@ -37,7 +49,11 @@ describe('customFetch', () => {
3749 const body = '{"test":"data"}' ;
3850 mockFetch . mockResolvedValueOnce ( {
3951 ok : true ,
40- headers : { get : ( ) => 'application/json' } ,
52+ headers : new Headers ( {
53+ 'content-type' : 'application/json' ,
54+ 'per-page' : '10' ,
55+ 'total' : '100' ,
56+ } ) ,
4157 json : ( ) => Promise . resolve ( { } ) ,
4258 } ) ;
4359
@@ -52,7 +68,11 @@ describe('customFetch', () => {
5268 const body = [ 'test' , 'data' ] ;
5369 mockFetch . mockResolvedValueOnce ( {
5470 ok : true ,
55- headers : { get : ( ) => 'application/json' } ,
71+ headers : new Headers ( {
72+ 'content-type' : 'application/json' ,
73+ 'per-page' : '10' ,
74+ 'total' : '100' ,
75+ } ) ,
5676 json : ( ) => Promise . resolve ( { } ) ,
5777 } ) ;
5878
@@ -67,7 +87,11 @@ describe('customFetch', () => {
6787 const textResponse = 'Hello World' ;
6888 mockFetch . mockResolvedValueOnce ( {
6989 ok : true ,
70- headers : { get : ( ) => 'text/plain' } ,
90+ headers : new Headers ( {
91+ 'content-type' : 'text/plain' ,
92+ 'per-page' : '10' ,
93+ 'total' : '100' ,
94+ } ) ,
7195 text : ( ) => Promise . resolve ( textResponse ) ,
7296 } ) ;
7397
@@ -80,6 +104,11 @@ describe('customFetch', () => {
80104 ok : false ,
81105 status : 404 ,
82106 statusText : 'Not Found' ,
107+ headers : new Headers ( {
108+ 'content-type' : 'application/json' ,
109+ 'per-page' : '10' ,
110+ 'total' : '100' ,
111+ } ) ,
83112 json : ( ) => Promise . resolve ( errorResponse ) ,
84113 } ) ;
85114
@@ -109,7 +138,11 @@ describe('customFetch', () => {
109138 it ( 'should set correct headers' , async ( ) => {
110139 mockFetch . mockResolvedValueOnce ( {
111140 ok : true ,
112- headers : { get : ( ) => 'application/json' } ,
141+ headers : new Headers ( {
142+ 'content-type' : 'application/json' ,
143+ 'per-page' : '10' ,
144+ 'total' : '100' ,
145+ } ) ,
113146 json : ( ) => Promise . resolve ( { } ) ,
114147 } ) ;
115148
0 commit comments