简体   繁体   中英

Jest - [Function anonymous] in expect

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,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM