handle objects with no constructor in hasOwnProperty #7334
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm not super excited about the fix, so any feedback is welcome! It got hairy really quick, and looking at the docs for
Object.create
, I can see how this is a weird edge case that some have run into (including myself)Summary
This problem is discussed in #6730 .
In short, objects created using unconventional means such as
Object.create(null)
will not have aconstructor
property, causing an exception to be throw in "packages/expect/src/utils.js"hasOwnProperty
function.This odd behavior of JS objects is discussed in depth in the MDN docs here.
Test plan
Added a test case to the unit tests for
toMatchObject
matcher. The included test case will throw an errorTypeError: Cannot read property 'prototype' of undefined
without the included fix.Closes #6730