mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 07:17:04 +00:00
Merge pull request #23889 from MattTennison/fetch-mock
[fetch-mock] Add Mock Configuration Option Types
This commit is contained in:
@@ -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"
|
||||
});
|
||||
|
||||
Vendored
+18
-2
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user