diff --git a/types/fetch-mock/fetch-mock-tests.ts b/types/fetch-mock/fetch-mock-tests.ts index 459c8e1076..1d4b706105 100644 --- a/types/fetch-mock/fetch-mock-tests.ts +++ b/types/fetch-mock/fetch-mock-tests.ts @@ -6,6 +6,14 @@ fetchMock.mock("http://test.com", 200, { test: "header" } }); +fetchMock.mock("http//test.com", 200, { + query: { + searchValue: "apples" + } +}); +fetchMock.mock("http://test.com", 200, { + repeat: 2 +}); fetchMock.mock(/test\.com/, 200); fetchMock.mock(() => true, 200); fetchMock.mock((url, opts) => true, 200); @@ -73,3 +81,13 @@ const myMatcher: fetchMock.MockMatcherFunction = ( fetchMock.flush().then(resolved => resolved.forEach(console.log)); fetchMock.flush().catch(r => r); + +fetchMock.get("http://test.com", { + body: 'abc', + includeContentLength: false +}); + +fetchMock.get("http://test.com", { + body: 'abc', + redirectUrl: "http://example.org" +}); diff --git a/types/fetch-mock/index.d.ts b/types/fetch-mock/index.d.ts index 13563277b4..15babcba34 100644 --- a/types/fetch-mock/index.d.ts +++ b/types/fetch-mock/index.d.ts @@ -1,9 +1,10 @@ -// Type definitions for fetch-mock 5.12 +// Type definitions for fetch-mock 6.0 // Project: https://github.com/wheresrhys/fetch-mock // Definitions by: Alexey Svetliakov // Tamir Duberstein // Risto Keravuori // Chris Sinclair +// Matt Tennison // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -57,6 +58,17 @@ declare namespace fetchMock { * @default true */ sendAsJson?: boolean; + /** + * Setting this property to true will automatically add the + * content-length header + * @default true + */ + includeContentLength?: boolean; + /** + * The URL the response should be from (to imitate followed redirects + * - will set redirected: true on the response) + */ + redirectUrl?: string; } /** * Response: A Response instance - will be used unaltered @@ -100,6 +112,10 @@ declare namespace fetchMock { * key/value map of headers to match */ headers?: { [key: string]: string }; + /** + * key/value map of query strings to match, in any order + */ + query?: { [key: string]: string }; /** * as specified above */ @@ -115,7 +131,7 @@ declare namespace fetchMock { * any other routes defined (which may eventually result in an error * if nothing matches it). */ - times?: number; + repeat?: number; } type MockCall = [string, MockRequest];