使用Jest测试代码时出现错误

时间:2020-10-06 10:59:35

标签: jestjs

//这是我的filename.test.js文件

test('should setup to add the expense in the expense list', () => {
    const addExpense = {
        description: 'Wifi Bill',
        note: 'Heavy price',
        amount: 9000,
        createdAt: 2000
    }
    expect(addExpense).toEqual({
        type: 'ADD_EXPENSE',
        payload: {
            id: expect.any(String),
            ...addExpense
        }
    })
})

//这是我的动作创建者

 const addExpense = ({ description, note, amount, createdAt }) => ({
    type: 'ADD_EXPENSE',
    payload: {
        id: uuid(),
        description,
        note,
        amount,
        createdAt
    }
})

//不幸的是,运行test.js文件进行测试时遇到了这个错误

//我遇到了以下错误 Expect(received).toEqual(expected)//深度平等

    - Expected  - 4
    + Received  + 0

      Object {
    -   "payload": Object {
        "amount": 9000,
        "createdAt": 2000,
        "description": "Wifi Bill",
    -     "id": Any<String>,
        "note": "Heavy price",
    -   },
    -   "type": "ADD_EXPENSE",
      }

      27 |         createdAt: 2000
      28 |     }
    > 29 |     expect(addExpense).toEqual({
         |                        ^
      30 |         type: 'ADD_EXPENSE',
      31 |         payload: {
      32 |             id: expect.any(String),

      at Object.<anonymous> (src/test/actions/expense.test.js:29:24)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 failed, 4 passed, 5 total
Snapshots:   0 total
Time:        2.616 s
Ran all test suites.

0 个答案:

没有答案