简体   繁体   English

Jest - [匿名函数] in expect

[英]Jest - [Function anonymous] in expect

Jest expects the expected Cell property value to be [Function anonymous] . Jest 期望预期的Cell属性值为[Function anonymous]

What is correct syntax for that?什么是正确的语法?

() => {} seems to be [Function Cell] thus test fails. () => {}似乎是[Function Cell]因此测试失败。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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