You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it("matches the desired object",()=>{constactual=[null,{key: "value"}];expect(actual).toPartiallyContain({key: "value"});});
What you did:
By a fluke of data generation, some of the elements in an array returned in our code could contain null. These values would be filtered out later, but they were nevertheless produced by the function under test.
The expectation was that these null values would be skipped by the toPartiallyContain matcher as non-matches, but it would still find candidate objects. That is, I'd expect the test above to pass because the array does contain a matching object as one of the later elements.
What happened (please provide anything you think will help):
The matcher throws an exception when attempting to access the hasOwnProperty member of the null element:
Cannot read properties of null (reading 'hasOwnProperty')
A similar exception is also raised if an element is undefined.
Bug
package
version: 3.2.3node
version: 16.19.0npm
version: 8.19.3Relevant code or config:
What you did:
By a fluke of data generation, some of the elements in an array returned in our code could contain
null
. These values would be filtered out later, but they were nevertheless produced by the function under test.The expectation was that these
null
values would be skipped by thetoPartiallyContain
matcher as non-matches, but it would still find candidate objects. That is, I'd expect the test above to pass because the array does contain a matching object as one of the later elements.What happened (please provide anything you think will help):
The matcher throws an exception when attempting to access the
hasOwnProperty
member of thenull
element:A similar exception is also raised if an element is
undefined
.The origin of the exception is in the
containsEntry
utility function when evaluating the first expression. As such:toIncludeAllPartialMembers
matcher if, like the earlier example, the "actual" array contains anull
-ish valuetoContainEntry
,toContainEntries
, andtoContainAllEntries
matchers are affected if the "actual" object is itselfnull
-ishReproduction repository (if possible):
Unfortunately it isn't public, but I could prepare something if the example above isn't sufficient.
The text was updated successfully, but these errors were encountered: