Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 减速器测试中的GET_失败收到错误的返回_Reactjs_Jestjs - Fatal编程技术网

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
});