本文整理汇总了TypeScript中fetch-mock.once函数的典型用法代码示例。如果您正苦于以下问题:TypeScript once函数的具体用法?TypeScript once怎么用?TypeScript once使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了once函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('decrements loading count when requests fail', async () => {
fetchMock.once('*', {
body: { settings: {} },
});
fetchMock.once('*', {
status: 400,
body: 'invalid',
});
const { uiSettingsApi } = setup();
const done$ = new Rx.Subject();
const promise = uiSettingsApi
.getLoadingCount$()
.pipe(
takeUntil(done$),
toArray()
)
.toPromise();
await uiSettingsApi.batchSet('foo', 'bar');
await expect(uiSettingsApi.batchSet('foo', 'bar')).rejects.toThrowError();
done$.next();
await expect(promise).resolves.toEqual([0, 1, 0, 1, 0]);
});
示例2: test
test('Schema migration displaying data loss', async t => {
// configure HTTP mocks
fetchMock.once(systemAPIEndpoint, JSON.parse(mockedPullProjectResponse1))
fetchMock.once(systemAPIEndpoint, JSON.parse(mockedPushSchema1ResponseError))
// dummy migration data
const projectFile = 'project.graphcool'
const env = testEnvironment({})
env.resolver.write(projectFile, mockModifiedProjectFile1)
env.resolver.write(graphcoolConfigFilePath, '{"token": ""}')
const props = { force: true }
env.out.prefix((t as any)._test.title, `$ graphcool push`)
await t.notThrows(
push(props, env)
)
t.is(env.resolver.read(projectFile), mockModifiedProjectFile1)
})
示例3:
headers: {
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);
fetchMock.once("http://test.com", 200);
fetchMock.mock(/test/, "test").mock(/test/, { a: "b" });
fetchMock.mock(/test/, {
status: 200,
headers: {
test: "test"
},
body: {
a: "b"
}
});
fetchMock.restore().reset();
(fetchMock.calls().matched[0][1] as RequestInit).body;