Closed as not planned
Description
Version
29.4.3
Steps to reproduce
- Clone my repo at https://github.com/chasingmaxwell/jest-bug-reproduce
- Run
yarn
- Run
yarn test
- See that some tests fail which should pass while other tests pass which should fail.
Expected behavior
- Using
objectContaining
to assert objects contain a property with a Map value when that Map has different entries than the expectation should fail.
// This should fail, but it passes
expect({ aMap: new Map([[1, 1]]) }).toEqual(
expect.objectContaining({
aMap: new Map([[2, 2]]),
})
);
- Using
not.objectContaining
to assert objects do not contain a property with an identical Map value should pass when the entries are not identical.
// This should pass, but it fails
expect({ aMap: new Map([[1, 1]]) }).toEqual(
expect.not.objectContaining({
aMap: new Map([[2, 2]]),
})
);
- Using
expect().not.toEqual(expect.objectContaining())
to assert objects do not contain a property with an identical Map value should pass when the entries are not identical.
// This should pass, but it fails
expect({ aMap: new Map([[1, 1]]) }).not.toEqual(
expect.objectContaining({
aMap: new Map([[2, 2]]),
})
);
Actual behavior
-
Using
objectContaining
to assert objects contain a property with a Map value when that Map has different entries than the expectation passes. -
Using
not.objectContaining
to assert objects do not contain a property with an identical Map value fails even when the entries are not identical. -
Using
expect().not.toEqual(expect.objectContaining())
to assert objects do not contain a property with an identical Map value fails even when the entries are not identical.
Additional context
It would seem that when matching against Map values, expect.objectContaining
will always pass and expect.not.objectContaining
will always fail. This may be related to these issues:
- Document expect(.not).(array|object)Containing()'s actual behavior #11157
- objectContaining not matching valid subset per docs #11126
- objectContaining should be recursive but isn't #10462
- expect.not.objectContaining() does not match documentation #10186
Environment
System:
OS: macOS 13.0.1
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 16.14.2 - ~/.asdf/installs/nodejs/16.14.2/bin/node
Yarn: 1.22.19 - ~/.asdf/installs/nodejs/16.14.2/.npm/bin/yarn
npm: 8.5.0 - ~/.asdf/plugins/nodejs/shims/npm
npmPackages:
jest: ^29.4.3 => 29.4.3