Merge pull request #23889 from MattTennison/fetch-mock

[fetch-mock] Add Mock Configuration Option Types
This commit is contained in:
Benjamin Lichtman
2018-02-28 13:40:18 -08:00
committed by GitHub
2 changed files with 36 additions and 2 deletions
+18
View File
@@ -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"
});
+18 -2
View File
@@ -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 <https://github.com/asvetliakov>
// Tamir Duberstein <https://github.com/tamird>
// Risto Keravuori <https://github.com/merrywhether>
// Chris Sinclair <https://github.com/chrissinclair>
// Matt Tennison <https://github.com/matttennison>
// 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];