diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..4d3c0a8 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,27 @@ +import { InspectionFilter, InspectionOptions, FetchMockStatic, MockCall, FetchMockSandbox } from 'fetch-mock'; + +declare global { + namespace jest { + interface Matchers { + toHaveFetched(filter?: InspectionFilter, options?: InspectionOptions): R; + toHaveLastFetched(filter?: InspectionFilter, options?: InspectionOptions): R; + toHaveNthFetched(n: number, filter?: InspectionFilter, options?: InspectionOptions): R; + toHaveFetchedTimes(times: number, filter?: InspectionFilter, options?: InspectionOptions): R; + toBeDone(filter?: InspectionFilter): R; + } + } +} + + +interface FetchMockJest { + // Reset the call history + mockClear(): void; + // Remove all configured mocks + mockReset(): void; + // Enable sandbox mode + sandbox(): jest.MockInstance & FetchMockSandbox; +} + +declare const fetchMockJest: FetchMockJest & jest.MockInstance & FetchMockStatic + +export = fetchMockJest; diff --git a/package.json b/package.json index ce751d1..187eae9 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Jest wrapper for fetch-mock, a comprehensive stub for fetch", "main": "server.js", "browser": "browser.js", + "types": "index.d.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" },