Reactjs 减速器测试中的GET_失败收到错误的返回
实际减速器:Reactjs 减速器测试中的GET_失败收到错误的返回,reactjs,jestjs,Reactjs,Jestjs,实际减速器: describe('get postals failed', () => { it(`it should handle ${GET_POSTAL}`, () => { const code = 'fail'; expect(reducer(state, { type: GET_POSTAL, code })).toEqual({ ...state, code, loading: true
describe('get postals failed', () => {
it(`it should handle ${GET_POSTAL}`, () => {
const code = 'fail';
expect(reducer(state, { type: GET_POSTAL, code })).toEqual({
...state,
code,
loading: true,
});
});
const payload = {
error: {
errorMessage: 'test',
postalInfo: {},
}
};
state = reducer(state,{
GET_POSTAL_FAILED,
payload
});
expect(state).toEqual({
...state,
error: payload.error,
loading: false,
});
})
在错误中:
case constants.GET_POSTAL_FAILED:
return {
...state,
error: action.payload.error,
loading: false,
};
我尝试了不同的方法,但它拒绝显示错误消息。当您使用
GET\u POSTAL\u FAILED
调用reducer时,您似乎没有在type
属性中设置它:
Error: expect(received).toEqual(expected) // deep equality
- Expected
+ Received
Object {
- "error": Object {
- "errorMessage": "test",
- "postalInfo": Object {},
- },
- "loading": false,
"postalInfo": Object {},
}
此外,您应该将对
reducer
的每次调用都放在it
中。当您使用GET\u POSTAL\u FAILED
调用reducer时,似乎没有在type
属性中设置它(即reducer(状态,{type:GET\u POSTAL\u FAILED,payload})
)。此外,您应该在it
@mgarcia ah ofc中调用reducer
。。。我没看到,哈哈,谢谢你!
reducer(state, {
type: GET_POSTAL_FAILED,
payload
});