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 throws TypeError when a source property is null #6235

Closed
massimonewsuk opened this issue May 23, 2018 · 6 comments
Closed

toMatchObject throws TypeError when a source property is null #6235

massimonewsuk opened this issue May 23, 2018 · 6 comments

Comments

@massimonewsuk
Copy link

test.only("foo", () => {
  expect({ foo: null }).toMatchObject({ foo: { bar: "baz" } });
});

This code gives a TypeError as opposed to a nice assertion error.

Both myself and my colleague have had this issue this week and both of us took about an hour to realise it was a problem with Jest and not our code.

@thymikee
Copy link
Collaborator

Please conform to issue template and provide a repro and detailed error message.

@SimenB
Copy link
Member

SimenB commented May 23, 2018

This is pretty bad...

Repro: https://repl.it/repls/PersonalVisibleCustomer
Error message:
image

Should be easy enough to fix though, mind sending a PR?

@massimonewsuk
Copy link
Author

@SimenB thanks for posting the shot etc

We're over-capacity at the moment so unfortunately unable to submit any PRs, but if things cool down and nobody's fixed it then I don't mind picking it up, thanks!

@SimenB
Copy link
Member

SimenB commented May 23, 2018

The stack trace before asynchronicity blows it away (on current master):

    TypeError: Cannot convert undefined or null to object
        at hasOwnProperty (<anonymous>)
        at Object.<anonymous>.exports.hasOwnProperty (/Users/simbekkh/repos/jest/packages/expect/build/utils.js:12:35)
        at Object.keys.every.key (/Users/simbekkh/repos/jest/packages/expect/build/utils.js:222:7)
        at Array.every (<anonymous>)
        at Array.Object.<anonymous>.exports.subsetEquality (/Users/simbekkh/repos/jest/packages/expect/build/utils.js:220:30)
        at eq (/Users/simbekkh/repos/jest/packages/expect/build/jasmine_utils.js:77:46)
        at equals (/Users/simbekkh/repos/jest/packages/expect/build/jasmine_utils.js:17:10)
        at Object.keys.every.key (/Users/simbekkh/repos/jest/packages/expect/build/utils.js:223:33)
        at Array.every (<anonymous>)
        at Array.Object.<anonymous>.exports.subsetEquality (/Users/simbekkh/repos/jest/packages/expect/build/utils.js:220:30)

@thymikee
Copy link
Collaborator

Closed via #6313, will be up in next patch release

@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 12, 2021
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

3 participants