Skip to content

Commit

Permalink
Match ObjectNotContaining documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ninevra committed Oct 26, 2020
1 parent 5672ec7 commit 03916a5
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions packages/expect/src/asymmetricMatchers.ts
Expand Up @@ -8,8 +8,6 @@

import {equals, fnNameFor, hasProperty, isA, isUndefined} from './jasmineUtils';

import {emptyObject} from './utils';

export class AsymmetricMatcher<T> {
protected sample: T;
$$typeof: symbol;
Expand Down Expand Up @@ -163,37 +161,22 @@ class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
);
}

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<string, unknown>)
: 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<string, unknown>)
: this.sample[property];

return true;
if (!hasProperty(other, property) || !equals(expected, other[property])) {
result = false;
break;
}
}

return this.inverse ? !result : result;
}

toString() {
Expand Down

0 comments on commit 03916a5

Please sign in to comment.