本文整理汇总了TypeScript中fetch-mock/es5/client.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should use supplied Content-Type', async () => {
fetchMock.get('*', {});
await kfetch({ pathname: '/my/path', headers: { 'Content-Type': 'CustomContentType' } });
expect(fetchMock.lastOptions()!.headers).toMatchObject({
'Content-Type': 'CustomContentType',
});
});
示例2: it
it('should use supplied pathname and querystring', async () => {
const { http } = setup();
fetchMock.get('*', {});
await http.fetch('/my/path', { query: { a: 'b' } });
expect(fetchMock.lastUrl()).toBe('http://localhost/myBase/my/path?a=b');
});
示例3: beforeEach
beforeEach(async () => {
fetchMock.get('*', { status: 404, body: { foo: 'bar' } });
try {
await kfetch({ pathname: '/my/path' });
} catch (e) {
error = e;
}
});
示例4: it
it('should reject on network error', async () => {
expect.assertions(1);
fetchMock.get('*', { throws: new Error('Network issue') });
try {
await kfetch({ pathname: 'my/path' });
} catch (e) {
expect(e.message).toBe('Network issue');
}
});