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 does not properly match Map values #13968

Closed
chasingmaxwell opened this issue Feb 28, 2023 · 5 comments
Closed

[Bug]: objectContaining does not properly match Map values #13968

chasingmaxwell opened this issue Feb 28, 2023 · 5 comments

Comments

@chasingmaxwell
Copy link

Version

29.4.3

Steps to reproduce

  1. Clone my repo at https://github.com/chasingmaxwell/jest-bug-reproduce
  2. Run yarn
  3. Run yarn test
  4. See that some tests fail which should pass while other tests pass which should fail.

Expected behavior

  1. 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]]),
  })
);
  1. 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]]),
  })
);
  1. 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

  1. Using objectContaining to assert objects contain a property with a Map value when that Map has different entries than the expectation passes.

  2. Using not.objectContaining to assert objects do not contain a property with an identical Map value fails even when the entries are not identical.

  3. 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:

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
@mrazauskas
Copy link
Contributor

Might be good idea to have expect.mapContaining() and expect.SetContaining().

In general it seems that expect does not support Maps and Sets at this moment. For example, see #11250

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 31, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants