Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: objectContaining matches non-object values #15420

Open
flovouin opened this issue Dec 18, 2024 · 0 comments
Open

[Bug]: objectContaining matches non-object values #15420

flovouin opened this issue Dec 18, 2024 · 0 comments

Comments

@flovouin
Copy link

Version

29.7.0

Steps to reproduce

expect(undefined).toEqual(expect.objectContaining({}));
expect('test').toEqual(expect.objectContaining({}));
expect(1).toEqual(expect.objectContaining({}));
// Expecting the array to contain an object.
expect([]).toEqual([expect.objectContaining({})]);

Expected behavior

All tests above should fail.

Actual behavior

All tests pass.

Additional context

The documentation states that:

expect.objectContaining(object) matches any received object that recursively matches the expected properties. That is, the expected object is a subset of the received object.

However objectContaining can match any type, not just objects. This leads to all sorts of tests unexpectedly passing.

Environment

System:
    OS: macOS 15.2
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 22.11.0 - ~/.asdf/installs/nodejs/22.11.0/bin/node
    npm: 10.9.0 - ~/.asdf/plugins/nodejs/shims/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant