const middlewares = [ thunk ];
const mockStore = configureStore(middlewares);
const originals = {
Actions: {}
};
const mocks = {
Actions: {
addPasswordResetRequest: spy(() =>{
return [
{type: REQUEST_ADD_PASSWORD_RESET_REQUEST},
{type: REQUEST_ADD_PASSWORD_RESET_REQUEST_SUCCESS}
];
})
}
}
//(have functions to mock actions)
...
it('should create an action to request a password reset', (done) => {
nock('http://localhost:8080/')
.post('/password-reset-requests')
.reply(200);
var email = "test@email.com";
const expectedActions= [
{type: REQUEST_ADD_PASSWORD_RESET_REQUEST},
{type: REQUEST_ADD_PASSWORD_RESET_REQUEST_SUCCESS}
];
const store = mockStore({}, [
{type: REQUEST_ADD_PASSWORD_RESET_REQUEST},
{type: REQUEST_ADD_PASSWORD_RESET_REQUEST_SUCCESS}
], done);
store.dispatch(Actions.addPasswordResetRequest(email));
unMockActions();
});
我得到的回应:
Error: Expected [ { type: 'REQUEST_ADD_PASSWORD_RESET_REQUEST' },
{type: 'REQUEST_ADD_PASSWORD_RESET_REQUEST_SUCCESS' } ] to equal
{type: 'REQUEST_ADD_PASSWORD_RESET_REQUEST' }
当我运行此代码时,我只返回第一个操作,而不是第二个。它不是一个列表,它只是一个动作。我需要测试动作的顺序,而不是是否调用了一个动作。