@@ -252,6 +252,8 @@ afterEach(global.afterEachFn);
252252
253253afterAll ( ( ) => {
254254 global . displayTestStats ( ) ;
255+ // restore fetch
256+ global . restoreFetch ( ) ;
255257} ) ;
256258
257259const TestObject = Parse . Object . extend ( {
@@ -387,10 +389,28 @@ function mockShortLivedAuth() {
387389 return auth ;
388390}
389391
392+ const originalFetch = global . fetch ;
393+
394+ global . restoreFetch = ( ) => {
395+ global . fetch = originalFetch ;
396+ }
397+
390398function mockFetch ( mockResponses ) {
391- global . fetch = jasmine . createSpy ( 'fetch' ) . and . callFake ( ( url , options = { } ) => {
399+ const spy = jasmine . createSpy ( 'fetch' ) ;
400+
401+ global . fetch = ( url , options = { } ) => {
402+ // Allow requests to the Parse Server to pass through WITHOUT recording in spy
403+ // This prevents tests from failing when they check that fetch wasn't called
404+ // but the Parse SDK makes internal requests to the Parse Server
405+ if ( typeof url === 'string' && url . includes ( serverURL ) ) {
406+ return originalFetch ( url , options ) ;
407+ }
408+
409+ // Record non-Parse-Server calls in the spy
410+ spy ( url , options ) ;
411+
392412 options . method ||= 'GET' ;
393- const mockResponse = mockResponses . find (
413+ const mockResponse = mockResponses ? .find (
394414 ( mock ) => mock . url === url && mock . method === options . method
395415 ) ;
396416
@@ -402,7 +422,11 @@ function mockFetch(mockResponses) {
402422 ok : false ,
403423 statusText : 'Unknown URL or method' ,
404424 } ) ;
405- } ) ;
425+ } ;
426+
427+ // Expose spy methods for test assertions
428+ global . fetch . calls = spy . calls ;
429+ global . fetch . and = spy . and ;
406430}
407431
408432
0 commit comments