本文整理匯總了TypeScript中moxios.stubRequest函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript stubRequest函數的具體用法?TypeScript stubRequest怎麽用?TypeScript stubRequest使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了stubRequest函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it("should respond with 200 on fixed/broken", async () => {
try {
moxios.stubRequest(
`${circleAPI}/project/github/ft-interactive/` +
`ft-ig-github-project-manager/23?circle-token=llama`,
{
status: 200,
response: TestCircleBuildPayload
}
);
moxios.stubRequest(`${slackAPI}/testing`, {
status: 200,
responseText: "ok"
});
sig = signBlob("llama", JSON.stringify(TestStatusEvent));
const server = app.listen(2222);
return request(server)
.post("/github")
.set("X-Hub-Signature", sig)
.set("X-Github-Event", "status")
.set("X-Github-Delivery", "abc456")
.send(TestStatusEvent)
.expect(200)
.then(() => server.close());
} catch (e) {
console.error(e);
}
});
示例2: it
it('should dispatch SIGNIN_FAILURE on failed signin', () => {
const user = {
email: 'test-user@andela.com',
};
moxios.stubRequest('/api/v1/auth/register/', {
status: 401,
response: {
message: 'Invalid Token',
},
});
const expectedActions = [
{payload: undefined,
type: 'SIGNIN_FAILURE',
},
];
const store = mockStore();
const gAuth = gapi.auth2.getAuthInstance();
return store.dispatch(actions.signIn(gAuth.currentUser.get()))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
示例3: it
it('should stub requests RegExp', (done) => {
moxios.stubRequest(/\/users\/\d*/, {
status: 200,
response: USER_FRED
});
axios.get('/users/12345').then(onFulfilled);
moxios.wait(() => {
let response = onFulfilled.getCall(0).args[0];
deepEqual(response.data, USER_FRED);
done();
});
});