【问题标题】:Jest throws an error " Received: serializes to the same string"Jest 抛出错误“已接收:序列化为相同的字符串”
【发布时间】:2020-07-01 08:34:29
【问题描述】:

我正在测试我的减速机。我不知道我在哪里犯错。你能帮我解决这个问题吗

case SET_CONFIRM_INFO:
      return {
        ...state,
        confirmFields: action.confirmFields,
        adding: (action.adding !== '') ? action.adding : [],
        checkInfo: action.checkInfo,
        getAddings: action.getAddings
      };

这是我的测试:

  it('SET_CONFIRM_INFO', () => {
    const action = {
      type: SET_CONFIRM_INFO,
      confirmFields: [1, 2, 4],
      adding: [1, 2, 3],
      checkInfo: { 1: 'a', 2: 'b' },
      getAddings: () => []
    }

    expect(pay(defaultState, action)).toEqual({
      ...defaultState,
      confirmFields: action.confirmFields,
      adding: action.adding,
      checkInfo: action.checkInfo,
      getAddings: () => []
    })
  })

和错误:

【问题讨论】:

    标签: reactjs unit-testing testing jestjs


    【解决方案1】:

    最有可能的问题是对象包含一个无法被 Jest 比较或检查的函数。看到这个答案:https://stackoverflow.com/a/60989588/3995566

    【讨论】:

      猜你喜欢
      • 2019-11-12
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多