@@ -83,13 +83,21 @@ const mockPostRefresh = (success: boolean) =>
8383
8484const mockNetworkErrorOnce = ( ) => fetchMock . mockImplementationOnce ( ( ) => Promise . reject ( ) ) ;
8585
86+ // Make `Headers` return a singleton for easier comparison in tests
87+ const originalHeaders = global . Headers ;
88+ const singleton = new originalHeaders ( ) ;
89+ vi . spyOn ( global , 'Headers' ) . mockImplementation ( function ( init ?: HeadersInit ) {
90+ return singleton ;
91+ } ) ;
92+
8693const makeRequest = ( method : RequestMethod = GET_METHOD ) => request ( apiPath , method , fetchOptions ) ;
8794const expectFetchToBeCalledWithCorrectParams = ( ) =>
8895 expect ( fetchMock ) . toBeCalledWith (
8996 fullApiUrl ,
9097 generateApiCallHeadersAndFetchOptions ( GET_METHOD , fetchOptions )
9198 ) ;
9299const expectRefreshFlowFetchesToBeCalledWithCorrectParams = ( ) => {
100+ expect ( fetchMock ) . toBeCalledTimes ( 2 ) ;
93101 expect ( fetchMock ) . toHaveBeenNthCalledWith (
94102 1 ,
95103 fullApiUrl ,
@@ -100,6 +108,16 @@ const expectRefreshFlowFetchesToBeCalledWithCorrectParams = () => {
100108 fullApiUrl ,
101109 expect . objectContaining ( generateApiCallHeadersAndFetchOptions ( GET_METHOD , refreshFetchOptions ) )
102110 ) ;
111+ // expect(fetchMock).toHaveBeenNthCalledWith(
112+ // 1,
113+ // fullApiUrl,
114+ // expect.objectContaining(generateApiCallHeadersAndFetchOptions(GET_METHOD, fetchOptions))
115+ // );
116+ // expect(fetchMock).toHaveBeenNthCalledWith(
117+ // 2,
118+ // fullApiUrl,
119+ // expect.objectContaining(generateApiCallHeadersAndFetchOptions(GET_METHOD, refreshFetchOptions))
120+ // );
103121} ;
104122const expectPostRefreshToBeCalled = ( called : boolean ) =>
105123 called ? expect ( postRefreshSpy ) . toBeCalledTimes ( 1 ) : expect ( postRefreshSpy ) . not . toBeCalled ( ) ;
0 commit comments