本文整理汇总了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());
});
});
开发者ID:gooddata,项目名称:gooddata-js,代码行数:11,代码来源:execute-afm.test.ts
示例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);
});
开发者ID:gooddata,项目名称:gooddata-js,代码行数:41,代码来源:user.test.ts
示例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');
});
开发者ID:austec-automation,项目名称:kibana,代码行数:12,代码来源:ui_settings_api.test.ts
示例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);
});
});
开发者ID:gooddata,项目名称:gooddata-js,代码行数:12,代码来源:project.test.ts
示例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);
});
});
开发者ID:gooddata,项目名称:gooddata-js,代码行数:12,代码来源:metadata.test.ts
示例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()
})
})
})
开发者ID:Workfront,项目名称:workfront-api,代码行数:22,代码来源:getApiKey.spec.ts
注:本文中的fetch-mock.mock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论