[Bug]: Symbols result in misleading diffs (original) (raw)
Version
29.4.0
Steps to reproduce
const Foo = Symbol("foo"); test("mismatched symbols", () => { expect({ a: 1, [Foo]: {id: 1} }).toMatchObject({ a: 1, [Foo]: {id: 2} }); });
Expected behavior
A diff that indicates the different property:
- Expected - 1
+ Received + 1
Object {
"a": 1,
Symbol(foo): Object {
- "id": 2,
+ "id": 1,
},
}
Actual behavior
A diff that acts like the received object had no symbol property at all:
- Expected - 3
+ Received + 0
Object {
"a": 1,
- Symbol(foo): Object {
- "id": 2,
- },
}
Additional context
As a result of #13639, expect.toMatchObject can now compare symbol keys. However, getObjectSubset wasn't updated to match, so the resulting diffs can be misleading or confusing.
Environment
System: OS: macOS 13.1 CPU: (10) arm64 Apple M1 Pro Binaries: Node: 18.13.0 - ~/.nvm/versions/node/v18.13.0/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.19.3 - ~/.nvm/versions/node/v18.13.0/bin/npm npmPackages: jest: ^29.4.0 => 29.4.0