UNPKG

@fetch-mock/jest

Version:
42 lines (41 loc) 1.13 kB
import { FetchMock, defaultFetchMockConfig, } from 'fetch-mock'; import './jest-extensions.js'; class FetchMockJest extends FetchMock { mockClear() { this.clearHistory(); return this; } mockReset(options = { includeSticky: false }) { this.removeRoutes({ ...options, includeFallback: true, }); return this.mockClear(); } mockRestore(options) { this.unmockGlobal(); return this.mockReset(options); } } export function manageFetchMockGlobally(jest) { const { clearAllMocks, resetAllMocks, restoreAllMocks } = jest; jest.clearAllMocks = () => { clearAllMocks.apply(jest); fetchMockJest.mockClear(); return jest; }; jest.resetAllMocks = () => { resetAllMocks.apply(jest); fetchMockJest.mockReset(); return jest; }; jest.restoreAllMocks = () => { restoreAllMocks.apply(jest); fetchMockJest.mockRestore(); return jest; }; } const fetchMockJest = new FetchMockJest({ ...defaultFetchMockConfig, }); export default fetchMockJest;