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

toMatchObject seems to ignore Map and Set #11250

Closed
fabiosantoscode opened this issue Mar 29, 2021 · 11 comments
Closed

toMatchObject seems to ignore Map and Set #11250

fabiosantoscode opened this issue Mar 29, 2021 · 11 comments

Comments

@fabiosantoscode
Copy link

fabiosantoscode commented Mar 29, 2021

🐛 Bug Report

I've noticed that .toMatchObject ignores any Map and Set objects, silently accepting different things.

To Reproduce

Steps to reproduce the behavior:

Attempt to match an object against a Map or Set, for example:

expect({ hello: 'world' }).toMatchObject(new Set()); // Passes, should fail
expect({ hello: [] }).toMatchObject({ hello: new Map() }); // Passes, should fail

Expected behavior

The test should fail, because Map and Set are always different from strings and arrays.

Link to repl or repo (highly encouraged)

https://replit.com/@fabiosantoscode/jest-playground#matchobject.test.js

envinfo

  System:
    OS: Linux 5.8 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  Binaries:
    Node: 15.4.0 - ~/.nvm/versions/node/v15.4.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v15.4.0/bin/yarn
    npm: 7.6.3 - ~/.nvm/versions/node/v15.4.0/bin/npm
  npmPackages:
    jest: 26.2.2 => 26.2.2 

(and also in the REPL, which has this envinfo)

  System:
    OS: Linux 5.4 Debian GNU/Linux 9 (stretch) 9 (stretch)
    CPU: (4) x64 Intel(R) Xeon(R) CPU @ 2.30GHz
  Binaries:
    Node: 12.21.0 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.11 - /usr/local/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3 
@fabiosantoscode
Copy link
Author

May be related to #11112 -- RegExp objects also have the same effect as Map in this case.

@julienw
Copy link

julienw commented Feb 18, 2022

Just got into this as well. The fact that it silently accepts the value and passes the test is error-prone.

@fabiosantoscode
Copy link
Author

Fixed the REPL to make it clearer. I started experimenting with regexes shortly after I posted this issue, but then I didn't revert my changes :)

@github-actions
Copy link

This issue is stale because it has been open for 1 year 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 Feb 18, 2023
@fabiosantoscode
Copy link
Author

fabiosantoscode commented Feb 18, 2023

I've updated the reproduction REPL to use Jest 29.4.3, and can still reproduce this issue.

@szimek
Copy link

szimek commented Dec 19, 2023

I've just ran into this issue when trying to use expect.objectContains with a value that is a Map.

This issue describes the problem: #13968, but is unfortunately already closed.

Copy link

This issue is stale because it has been open for 1 year 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 Dec 18, 2024
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 Jan 17, 2025
@julienw
Copy link

julienw commented Jan 17, 2025

Is it possible to reopen ? Unless it's been fixed

@fabiosantoscode
Copy link
Author

I can't reopen it, and I don't really feel like trying to repro again with the newest version.

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 Feb 18, 2025
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

4 participants