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
1 Answer
Reset to default 8You 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
版权声明:本文标题:javascript - Jest - [Function anonymous] in expect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741453092a2379601.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论