question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

toMatchObject throws TypeError when a source property is null

See original GitHub issue
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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
SimenBcommented, 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?

0reactions
github-actions[bot]commented, May 12, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found