【发布时间】:2018-06-19 03:51:51
【问题描述】:
我的 react native 应用程序中有以下测试,但测试应该失败(因为返回的操作不等于我在 expectedActions 中输入的操作。我的猜测是它通过了,因为 expect 测试测试完成后运行。
如何强制测试等到 promise 完成并且期望测试运行?还有其他方法吗?
describe('authorize actions', () => {
beforeEach(() => {
store = mockStore({});
});
it('should create an action to signify successful auth', () => {
auth.authorize.mockImplementation(() => Promise.resolve({"something": "value"}));
const expectedActions = [{"type":"AUTHORIZE_RESPONSE","payload":{"something":"sdklfjsdf"}}];
authorizeUser(store.dispatch, store.state).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
})
});
【问题讨论】:
标签: javascript reactjs unit-testing redux jestjs