本文整理汇总了TypeScript中fetch-mock.mock函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mock函数的具体用法?TypeScript mock怎么用?TypeScript mock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should return correct execution response', () => {
fetchMock.mock(
fakeExecuteAfmUri,
{ status: 200, body: getPollingResponseBody() }
);
return createExecuteAfm().getExecutionResponse('myFakeProjectId', getExecution())
.then((responses: Execution.IExecutionResponse) => {
expect(responses).toEqual(getExecutionResponse());
});
});
示例2: it
it('should resolve false if user logged in but project not available', () => {
const projectId = 'myProject';
const profileId = 'asdf1234';
const profileUri = `/gdc/account/profile/${profileId}`;
fetchMock.mock(
'/gdc/account/profile/current',
{
status: 200,
body: JSON.stringify({
accountSetting: {
links: {
self: profileUri
}
}
})
}
);
fetchMock.mock(
`/gdc/account/profile/${profileId}/projects?offset=0&limit=100`,
{
status: 200,
body: JSON.stringify({
projects: {
paging: {
offset: 0,
limit: 100,
totalCount: 2
},
items: [
{ project: { links: { self: '/gdc/projects/differentproject' } } },
{ project: { links: { self: '/gdc/projects/anotherproject' } } }
]
}
})
}
);
return expect(createUser().isLoggedInProject(projectId)).resolves.toEqual(false);
});
示例3: it
it('Buffers are always clear of previously buffered changes', async () => {
fetchMock.mock('*', {
body: { settings: {} },
});
const { uiSettingsApi } = setup();
uiSettingsApi.batchSet('foo', 'bar');
uiSettingsApi.batchSet('bar', 'foo');
await uiSettingsApi.batchSet('bar', 'box');
expect(fetchMock.calls()).toMatchSnapshot('two requests, second only sends bar, not foo');
});
示例4: it
it('should return an array of dataSets', () => {
fetchMock.mock(
'/gdc/md/myFakeProjectId/query/datasets',
{
status: 200,
body: JSON.stringify({ query: { entries: [{}, {}] } })
}
);
return createProject().getDatasets('myFakeProjectId').then((result: any) => {
expect(result.length).toBe(2);
});
});
示例5: it
it('should return rejected promise if 400 returned from backend', () => {
fetchMock.mock(
using2Uri,
{ status: 400, body: JSON.stringify({}) }
);
return createMd().getObjectUsingMany(projectId, objects, { types }).then(() => {
throw new Error('Should reject the promise on 400 response');
}).catch((err: any) => {
expect(err.response.status).toBe(400);
});
});
示例6: it
it('should get and then clear the apiKey', function(done) {
fetchMock.mock(
(url, opts) => opts.body.indexOf('getApiKey') !== -1,
'{"data": {"result": "baz"}}',
{name: 'getApiKey'}
)
fetchMock.mock(
(url, opts) => opts.body.indexOf('clearApiKey') !== -1,
'{"data": {"success": true}}',
{name: 'clearApiKey'}
)
this.api.getApiKey('foo', 'bar').then((apiKey) => {
should(apiKey).equal('baz')
should(fetchMock.calls('getApiKey')).length(1)
should(this.api._httpOptions.headers).have.property('apiKey').eql('baz')
this.api.clearApiKey().then(() => {
should(this.api._httpOptions.headers).not.have.property('apiKey')
done()
})
})
})