javascript - Jest/expect "toEquals" failing with undefined properties
问题描述
I'm using expect(item).toEqual(otherItem)
. Acording to everything I've read, expect({ a: "a", b: undefined }).toEqual({ a: "a" })
should pass. Otherwise I should be using toStrictEqual
. E.g. here, in "basic matches".
However, I'm getting a failure with the output:
Array [
Object {
+ "alertId": undefined,
"attributes": Array [],
"destination": "_b",
"kind": "kind",
"linkable": "Unlinkable",
"source": "_a",
+ "validFrom": undefined,
+ "validTo": undefined,
},
- Object {
- "attributes": Array [],
- "destination": "_c",
- "kind": "kind",
- "linkable": "Unlinkable",
- "source": "_a",
- },
]
Any idea why?
解决方案
啊。我是个白痴。开玩笑没有错,测试正确地失败了。我读错了 Jest 的输出。
这是说整个对象:
- Object {
- "attributes": Array [],
- "destination": "_c",
- "kind": "kind",
- "linkable": "Unlinkable",
- "source": "_a",
从数组中丢失。尽管它也报告undefined
了差异,但这并不是导致toEqual
失败的原因。注意destination
是不同的。测试应该返回两个对象。
推荐阅读
- apache-spark - 在 Spark 中阅读 Kafka 主题尾部
- javascript - 数据更改时,Vue动态组件不会在v-for循环内重新渲染
- java - 用于 double 和 float 类型的 Java 通用数学算术
- php - Laravel 5.2 是否支持 PHP 7.2
- ssis - SQL Server 2019 - 作业 (SSIS) 失败并出现错误“系统找不到指定的文件”
- samba - 从 Windows 打印到许多不同的打印机
- video - 如何使用电子实现文件浏览器等视频缩略图
- mysql - 如何解决 docker 容器延迟
- angular - 对象中的角度排序项目
- c# - HttpWebrequest 中 HTTP 标头的严格排序