diff --git a/packages/expect/src/asymmetricMatchers.ts b/packages/expect/src/asymmetricMatchers.ts index dd0026bc72de..a6c12c3f6188 100644 --- a/packages/expect/src/asymmetricMatchers.ts +++ b/packages/expect/src/asymmetricMatchers.ts @@ -8,8 +8,6 @@ import {equals, fnNameFor, hasProperty, isA, isUndefined} from './jasmineUtils'; -import {emptyObject} from './utils'; - export class AsymmetricMatcher { protected sample: T; $$typeof: symbol; @@ -163,40 +161,28 @@ class ObjectContaining extends AsymmetricMatcher> { ); } - if (this.inverse) { - for (const property in this.sample) { - if ( - hasProperty(other, property) && - equals(this.sample[property], other[property]) && - !emptyObject(this.sample[property]) && - !emptyObject(other[property]) - ) { - return false; - } - } + let result = true; - return true; - } else { - for (const property in this.sample) { - if ( - typeof this.sample[property] === 'object' && - !(this.sample[property] instanceof AsymmetricMatcher) - ) { - this.sample[property] = objectContaining( - this.sample[property] as Record, - ); - } - - if ( - !hasProperty(other, property) || - !equals(this.sample[property], other[property]) - ) { - return false; - } + for (const property in this.sample) { + if ( + typeof this.sample[property] === 'object' && + !(this.sample[property] instanceof AsymmetricMatcher) + ) { + this.sample[property] = objectContaining( + this.sample[property] as Record, + ); } - return true; + if ( + !hasProperty(other, property) || + !equals(this.sample[property], other[property]) + ) { + result = false; + break; + } } + + return this.inverse ? !result : result; } toString() {