UNPKG

@fetch-mock/jest

Version:
45 lines (44 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.manageFetchMockGlobally = manageFetchMockGlobally; const fetch_mock_1 = require("fetch-mock"); require("./jest-extensions.js"); class FetchMockJest extends fetch_mock_1.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); } } 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({ ...fetch_mock_1.defaultFetchMockConfig, }); exports.default = fetchMockJest;