From 03916a5c977112f1182023cc3cf25dbc96559b03 Mon Sep 17 00:00:00 2001 From: ninevra Date: Sun, 25 Oct 2020 21:32:36 -0700 Subject: [PATCH] Match ObjectNotContaining documentation --- packages/expect/src/asymmetricMatchers.ts | 43 +++++++---------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/packages/expect/src/asymmetricMatchers.ts b/packages/expect/src/asymmetricMatchers.ts index 280ebc9d5fe2..0e9076d5c5f1 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,37 +161,22 @@ 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) { - const expected = - typeof this.sample[property] === 'object' && - !(this.sample[property] instanceof AsymmetricMatcher) - ? objectContaining(this.sample[property] as Record) - : this.sample[property]; - - if ( - !hasProperty(other, property) || - !equals(expected, other[property]) - ) { - return false; - } - } + for (const property in this.sample) { + const expected = + typeof this.sample[property] === 'object' && + !(this.sample[property] instanceof AsymmetricMatcher) + ? objectContaining(this.sample[property] as Record) + : this.sample[property]; - return true; + if (!hasProperty(other, property) || !equals(expected, other[property])) { + result = false; + break; + } } + + return this.inverse ? !result : result; } toString() {