javascript - 开玩笑 - 期待中的 [功能匿名]
问题描述
Jest 期望预期的Cell
属性值为[Function anonymous]
。
什么是正确的语法?
() => {}
似乎[Function Cell]
因此测试失败。
const expected =
[{ Cell: () => {}, Header: '', accessor: () => {}, disableSortBy: true, id: 18, width: 50 }];
expect(result).toBe(expected);
安慰:
$ 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,
解决方案
您需要告诉它需要数组,然后是对象。每个对象都需要指定其类型或值
尝试这样的事情
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);
推荐阅读
- python - 拆分具有多个排序序列的 numpy 数组
- ffmpeg - ffmpeg Makefile中的“全是”是什么意思
- python - 从熊猫数据框的两列生成矩阵
- python - 如何让我的 LSTM-Autoencoder 准确度更高?
- python - 如何使用 python 而不是 Excel 宏自定义我的 csv 文件
- node.js - 在 netlify 上部署后 HTTP 获取响应 404
- spring-boot - 将 Spring Cloud Function 部署到 OpenFaaS
- three.js - react-three/fiber 中的相机旋转和 OrbitControls
- azure - 启用 Arc 的 kubernetes - Envoy 丢失了吗?证书 ?集群重新启动并在侦听器上返回连接重置后
- google-cloud-platform - 有没有办法在本地运行 GCP 工作流?