本文整理汇总了TypeScript中moxios.stubOnce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript stubOnce函数的具体用法?TypeScript stubOnce怎么用?TypeScript stubOnce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stubOnce函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('Should stub and find multiple requests by method', (done) => {
moxios.stubOnce('PUT', '/users/12345', {
status: 204
});
moxios.stubOnce('GET', '/users/12346', {
status: 200,
response: USER_FRED
});
axios.put('/users/12345', USER_FRED).then(onFulfilled);
axios.get('/users/12346', {}).then(onFulfilled);
moxios.wait(() => {
equal(onFulfilled.calledTwice, true);
let response1 = onFulfilled.getCall(0).args[0];
let response2 = onFulfilled.getCall(1).args[0];
equal(response1.status, 204);
equal(response2.status, 200);
equal(response2.data.firstName, 'Fred');
let request = moxios.requests.get('PUT', '/users/12345');
notEqual(request, undefined);
request = moxios.requests.get('GET', '/users/12346');
notEqual(request, undefined);
done();
});
});
示例2: it
it('POSTs to Circle for env-vars beginning with "DEPLOY_VAR_"', (done: MochaDone) => {
const api = new Circle("test", "test", "");
moxios.stubOnce(
"POST",
`/project/github/test/test/envvar?circle-token=llama`,
{
status: 200,
response: {
LLAMA: "duck"
}
}
);
const resultsPromise = api.addEnvVars("test", "test", {
DEPLOY_VAR_HERPA: "derpa",
DEPLOY_VAR_LLAMA: "duck"
});
moxios.wait(async () => {
const results = await resultsPromise;
const firstRequest = moxios.requests.at(0);
const secondRequest = moxios.requests.at(1);
// @TODO uncomment after DefinitelyTyped#20466 fixed
// JSON.parse(firstRequest.config.data).name.should.equal('HERPA');
// JSON.parse(firstRequest.config.data).value.should.equal('derpa');
// JSON.parse(secondRequest.config.data).name.should.equal('LLAMA');
// JSON.parse(secondRequest.config.data).value.should.equal('duck');
done();
});
});