玩笑 - 期待中的[匿名函数]

Roo*_*ode 8 javascript jestjs

Jest 预计预期Cell财产价值为[Function anonymous]

正确的语法是什么?

() => {}似乎[Function Cell]因此测试失败。

const expected =
      [{ Cell: () => {}, Header: '', accessor: () => {}, disableSortBy: true, id: 18, width: 50 }];

expect(result).toBe(expected);
Run Code Online (Sandbox Code Playgroud)

安慰:

 $ jest test

----
    - Expected  - 1
    + Received  + 1

    @@ -1,8 +1,8 @@
      Array [
        Object {
    -     "Cell": [Function Cell],
    +     "Cell": [Function anonymous],
          "Header": "",
          "accessor": [Function accessor],
          "disableSortBy": true,
          "id": 18,
          "width": 50,
Run Code Online (Sandbox Code Playgroud)

har*_*rry 8

您需要告诉它需要数组,然后需要其上的对象。每个对象都需要指定其类型或值

尝试这样的事情

const expected = expect.arrayContaining([
    expect.objectContaining({
      Cell: expect.any(Function),
      Header: expect.any(String),
      accessor: expect.any(Function),
      disableSortBy: expect.any(Boolean),
      /*...........so..on............*/
    })
  ]);

expect(result).toEqual(expected);

Run Code Online (Sandbox Code Playgroud)