本文整理汇总了TypeScript中fetch-mock.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('brokenProofs', (t) => {
FetchMock.get(`${naval.facebook.url}b`, naval.facebook.body)
FetchMock.get(`${naval.github.url}b/raw`, naval.github.body)
FetchMock.get(`${naval.twitter.url}b`, { body: '', status: 400 })
t.plan(2)
validateProofs({ account: navalAccounts }, undefined, 'naval.id')
.then((proofs) => {
t.equal(proofs.length, 3)
t.equal(proofs.filter(x => x.valid).length, 2)
FetchMock.restore()
})
})
示例2: it
it('should folow multiple redirects', () => {
fetchMock.get('/some/url', { status: 202, headers: { Location: '/other/url' } });
fetchMock.get('/other/url', { status: 202, headers: { Location: '/last/url' } });
fetchMock.get('/last/url', { status: 200, body: 'Poll result with redirects' });
return createXhr().ajax('/some/url', { pollDelay: 0 }).then((r) => {
expect(r.response.status).toBe(200);
expect(fetchMock.calls('/some/url').length).toBe(1);
expect(fetchMock.calls('/other/url').length).toBe(1);
expect(fetchMock.calls('/last/url').length).toBe(1);
expect(r.getData()).toBe('Poll result with redirects');
});
});
示例3: test
test('Succeeding project creation with remote schema file', async t => {
const name = 'MyProject'
const schemaUrl = 'https://graphqlbin/project.graphql'
// configure HTTP mocks
fetchMock.post(systemAPIEndpoint, JSON.parse(mockedCreateProjectResponse))
const schema = simpleTwitterSchema
fetchMock.get(schemaUrl, schema)
// create dummy project data
const props = {name, schemaUrl}
// prepare environment
const env = testEnvironment({})
env.resolver.write(graphcoolConfigFilePath, '{"token": "abcdefgh"}')
env.out.prefix((t as any)._test.title, `$ graphcool init -s ${schemaUrl} -n ${name}`)
await t.notThrows(
initCommand(props, env)
)
const expectedProjectFileContent = mockProjectFile1
t.is(env.resolver.read(graphcoolProjectFileName), expectedProjectFileContent)
t.is(readProjectIdFromProjectFile(env.resolver, graphcoolProjectFileName), 'abcdefghijklmn')
t.is(readVersionFromProjectFile(env.resolver, graphcoolProjectFileName), '1')
})
示例4: 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',
});
});
示例5: test
test('Succeeding auth without token', async t => {
// configure HTTP mocks
fetchMock.post(`${authEndpoint}/create`, {})
fetchMock.get(`${authEndpoint}/*`, {
authToken: testToken
})
fetchMock.post(`${systemAPIEndpoint}`, {
data: {
viewer: {
user: {
id: 'abcdefghik'
}
}
}
})
// configure auth dependencies
const env = testEnvironment({})
const authServer = new TestAuthServer()
env.out.prefix((t as any)._test.title, '$ graphcool auth')
// authenticate
await t.notThrows(
authCommand({}, env, authServer)
)
// verify result
const {token} = JSON.parse(env.resolver.read(graphcoolConfigFilePath))
t.is(token, testToken)
})
示例6: it
it('gets orderbook with default page options when none are provided', async () => {
const urlWithQuery = `${url}?baseTokenAddress=${
request.baseTokenAddress
}&page=1&per_page=100"eTokenAddress=${request.quoteTokenAddress}`;
fetchMock.get(urlWithQuery, orderbookJSON);
const orderbook = await relayerClient.getOrderbookAsync(request);
expect(orderbook).to.be.deep.equal(orderbookResponse);
});
示例7: beforeEach
beforeEach(async () => {
fetchMock.get('*', { status: 404, body: { foo: 'bar' } });
try {
await kfetch({ pathname: 'my/path' });
} catch (e) {
error = e;
}
});