Jestjs 我在使用Jest测试代码时出错

Jestjs 我在使用Jest测试代码时出错,jestjs,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(add

//这是我的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.
-预期为-4
+收到+0
反对{
-“有效载荷”:对象{
“金额”:9000,
“createdAt”:2000年,
“说明”:“Wifi账单”,
-“id”:任何,
“注”:“重价”,
-   },
-“类型”:“添加费用”,
}
27 |创建日期:2000
28 |     }
>29 |预期(附加费用)。toEqual({
|                        ^
30 |键入:“添加费用”,
31 |有效载荷:{
32 | id:expect.any(字符串),
at Object.(src/test/actions/expense.test.js:29:24)
测试套件:1个失败,1个通过,共2个
测试:1次失败,4次通过,共5次
快照:共0个
时间:2.616秒
运行所有测试套件。

您没有调用操作创建者,请正确编写代码。