Skip to content

Commit

Permalink
Resolve stepping into non vanilla objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Good authored Oct 26, 2020
1 parent 6ff06e6 commit c523b65
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/expect/src/asymmetricMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,21 @@ class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
return true;
} else {
for (const property in this.sample) {
const expected =
typeof this.sample[property] === 'object' &&
!(this.sample[property] instanceof AsymmetricMatcher)
? objectContaining(this.sample[property] as Record<string, unknown>)
: this.sample[property];
let expected = this.sample[property];

if (typeof this.sample[property] === 'object') {
const samplePropertyPrototype = Object.getPrototypeOf(
this.sample[property],
);
if (
samplePropertyPrototype === Object.prototype ||
samplePropertyPrototype === Array.prototype
) {
expected = objectContaining(
this.sample[property] as Record<string, unknown>,
);
}
}

if (
!hasProperty(other, property) ||
Expand Down

0 comments on commit c523b65

Please sign in to comment.