本文整理汇总了TypeScript中fetch-mock.called函数的典型用法代码示例。如果您正苦于以下问题:TypeScript called函数的具体用法?TypeScript called怎么用?TypeScript called使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了called函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: should
this.api.getApiKey('foo', 'bar').then((apiKey) => {
should(apiKey).equal('baz')
should(fetchMock.called('getApiKey')).be.true()
should(fetchMock.called('generateApiKey')).be.false()
should(fetchMock.calls('getApiKey')).length(1)
this.api.getApiKey('foo', 'bar').then(function() {
should(fetchMock.calls('getApiKey')).length(1)
done()
})
})
示例2: it
it('should pass anything set on {body} option as the {body} property of the request in JSON format', () => {
let body = '';
let headers: Headers = new Headers();
(fetchMock as any).post('http://localhost/ping', (_: any, opts: any) => {
headers = opts.headers;
body = opts.body;
return 200;
});
potion.fetch('http://localhost/ping', {method: 'POST', body: {pong: true}});
expect(fetchMock.called('http://localhost/ping')).toBe(true);
expect(headers).not.toBeUndefined();
expect(headers.get('accept')).toEqual('application/json');
expect(headers.get('content-type')).toEqual('application/json');
expect(body.length).not.toBe(0);
expect(JSON.parse(body)).toEqual({pong: true});
});
示例3:
body: {
a: "b"
}
});
fetchMock.restore().reset();
(fetchMock.calls().matched[0][1] as RequestInit).body;
fetchMock.calls().unmatched[0][0].toUpperCase();
fetchMock.calls("http://test.com")[0][0].toUpperCase();
(fetchMock.calls("http://test.com")[0][1] as RequestInit).body;
const doneStatus: boolean = fetchMock.done();
const doneStatusArguments: boolean = fetchMock.done("http://test.com");
const calledStatus: boolean = fetchMock.called();
const calledStatusArguments = fetchMock.called("http://test.com");
(fetchMock.lastCall()[1] as RequestInit).body;
const lastUrl: string = fetchMock.lastUrl();
fetchMock.lastOptions();
fetchMock.get("http://test.com", 200);
fetchMock.getOnce("http://test.com", 200);
fetchMock.post("http://test.com", 200);
fetchMock.postOnce("http://test.com", 200);
fetchMock.put("http://test.com", 200);
fetchMock.putOnce("http://test.com", 200);
fetchMock.delete("http://test.com", 200);
fetchMock.deleteOnce("http://test.com", 200);
fetchMock.head("http://test.com", 200);
示例4:
let calls: fetchMock.MockCall[] = fetchMock.calls(/https?:\/\/test.com/, {
method: 'GET',
});
calls[0][0].toUpperCase();
calls[0].identifier.toUpperCase();
calls[0].isUnmatched;
calls = fetchMock.calls();
calls = fetchMock.calls(true);
calls = fetchMock.calls("http://test.com", "GET");
let doneStatus: boolean = fetchMock.done();
doneStatus = fetchMock.done(true);
doneStatus = fetchMock.done("http://test.com");
doneStatus = fetchMock.done(/https?:\/\/test.com/);
let calledStatus: boolean = fetchMock.called();
calledStatus = fetchMock.called(true);
calledStatus = fetchMock.called("http://test.com");
calledStatus = fetchMock.called(/https?:\/\/test.com/);
calledStatus = fetchMock.called("http://test.com", "GET");
calledStatus = fetchMock.called("http://test.com", {
method: "GET",
});
calledStatus = fetchMock.called((url: string, opts: fetchMock.MockRequest): boolean => {
return true;
});
calledStatus = fetchMock.called(fetchMock.MATCHED);
calledStatus = fetchMock.called(fetchMock.UNMATCHED);
let lastCall: fetchMock.MockCall = fetchMock.lastCall();
lastCall = fetchMock.lastCall(/https?:\/\/test.com/, {
示例5:
headers: {
"test": "test"
},
body: {
a: "b"
}
});
fetchMock.restore().reset();
(fetchMock.calls().matched[0][1] as RequestInit).body;
fetchMock.calls().unmatched[0][0].toUpperCase();
fetchMock.calls("http://test.com")[0][0].toUpperCase();
(fetchMock.calls("http://test.com")[0][1] as RequestInit).body;
fetchMock.called("http://test.com");
(fetchMock.lastCall()[1] as RequestInit).body;
fetchMock.lastUrl();
fetchMock.lastOptions();
fetchMock.get("http://test.com", 200)
fetchMock.post("http://test.com", 200)
fetchMock.put("http://test.com", 200)
fetchMock.delete("http://test.com", 200)
fetchMock.head("http://test.com", 200)
fetchMock.get("http://test.com", 200, {method: "GET"})
fetchMock.post("http://test.com", 200, {method: "POST"})
fetchMock.put("http://test.com", 200, {method: "PUT"})
fetchMock.delete("http://test.com", 200, {method: "DELETE"})
示例6: it
it('should not make request', () => {
expect(fetchMock.called('*')).toBe(false);
});