toMatchObject throws TypeError when a source property is null
See original GitHub issuetest.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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Jest toMatchObject throws TypeError - Stack Overflow
fetch.data.items[0] does not have a prototype. My guess is that under the hood jest's toMatchObject requires a prototype and fails.
Read more >TypeError: "x" is not a non-null object - JavaScript | MDN
TypeError : Property description must be an object: x (V8-based) ... Providing no object (like just a number), will throw an error: Object....
Read more >Expect · Jest
toMatchObject to check that a JavaScript object matches a subset of the properties of an object. const houseForSale = { bath: true, kitchen:...
Read more >API Reference | Vitest
toMatchObject asserts if an object matches a subset of the properties of an object. You can also pass an array of objects. This...
Read more >Expect / Should - Chai Assertion Library
If . or [] are part of an actual property name, they can be escaped by adding ... var badFn = function ()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is pretty bad…
Repro: https://repl.it/repls/PersonalVisibleCustomer Error message:
Should be easy enough to fix though, mind sending a PR?
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.