MCPcopy
hub / github.com/parse-community/parse-server / mockFetch

Function mockFetch

spec/helper.js:425–458  ·  view source on GitHub ↗
(mockResponses)

Source from the content-addressed store, hash-verified

423}
424
425function mockFetch(mockResponses) {
426 const spy = jasmine.createSpy('fetch');
427 fetchWasMocked = true; // Track that fetch was mocked for cleanup
428
429 global.fetch = (url, options = {}) => {
430 // Allow requests to the Parse Server to pass through WITHOUT recording in spy
431 // This prevents tests from failing when they check that fetch wasn't called
432 // but the Parse SDK makes internal requests to the Parse Server
433 if (typeof url === 'string' && url.includes(serverURL)) {
434 return originalFetch(url, options);
435 }
436
437 // Record non-Parse-Server calls in the spy
438 spy(url, options);
439
440 options.method ||= 'GET';
441 const mockResponse = mockResponses?.find(
442 (mock) => mock.url === url && mock.method === options.method
443 );
444
445 if (mockResponse) {
446 return Promise.resolve(mockResponse.response);
447 }
448
449 return Promise.resolve({
450 ok: false,
451 statusText: 'Unknown URL or method',
452 });
453 };
454
455 // Expose spy methods for test assertions
456 global.fetch.calls = spy.calls;
457 global.fetch.and = spy.and;
458}
459
460
461// This is polluting, but, it makes it way easier to directly port old tests.

Callers 14

oauth2.spec.jsFile · 0.85
weibo.spec.jsFile · 0.85
qq.spec.jsFile · 0.85
instagram.spec.jsFile · 0.85
linkedIn.spec.jsFile · 0.85
microsoft.spec.jsFile · 0.85
line.spec.jsFile · 0.85
wechat.spec.jsFile · 0.85
gpgames.spec.jsFile · 0.85
spotify.spec.jsFile · 0.85

Calls 1

findMethod · 0.65

Tested by

no test coverage detected