admin管理员组

文章数量:1289621

Jest expects the expected Cell property value to be [Function anonymous].

What is correct syntax for that?

() => {} seems to be [Function Cell] thus test fails.

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

expect(result).toBe(expected);

Console:

 $ 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,

Jest expects the expected Cell property value to be [Function anonymous].

What is correct syntax for that?

() => {} seems to be [Function Cell] thus test fails.

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

expect(result).toBe(expected);

Console:

 $ 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,
Share Improve this question edited Sep 30, 2020 at 14:34 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Sep 30, 2020 at 14:19 anmatikaanmatika 1,7016 gold badges23 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

You need to tell that it expects array and then objects on it. Each object needs to be specified its type or value

Try something like this

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

本文标签: javascriptJestFunction anonymous in expectStack Overflow