【发布时间】:2019-03-18 03:14:40
【问题描述】:
如何测试history.push inside action?
export const startLogout = () => {
return ( dispatch ) => {
return firebase
.auth()
.signOut()
.then(() => {
dispatch( logout() );
history.push( '/login' );
})
.catch( ( err ) => {
// Simple redirect to non existent route
history.push( '/oops' );
console.log( err );
});
};
};
test( 'should start logout', ( done ) => {
const store = createMockStore({});
store.dispatch( startLogout() ).then(() => {
const actions = store.getActions();
expect( actions[0] ).toEqual({
type: LOGOUT
});
const history = { push: jest.fn() };
expect( history.push ).toHaveBeenLastCalledWith( '/login' );
done();
}).catch((err) => {
console.log( err );
done();
});
});
这个当前代码给了我这个错误:
最后一次调用的预期模拟函数是: [“/登录”] 但它没有被调用。
谢谢
【问题讨论】:
标签: reactjs redux jestjs enzyme redux-thunk