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 c312e15 commit 25fad89
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 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,40 +161,28 @@ 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) {
if (
typeof this.sample[property] === 'object' &&
!(this.sample[property] instanceof AsymmetricMatcher)
) {
this.sample[property] = objectContaining(
this.sample[property] as Record<string, unknown>,
);
}

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<string, unknown>,
);
}

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

return this.inverse ? !result : result;
}

toString() {
Expand Down

0 comments on commit 25fad89

Please sign in to comment.