Skip to content

Commit

Permalink
Match ObjectNotContaining documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ninevra committed Nov 4, 2020
1 parent a4d69e1 commit e8b007b
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions packages/expect/src/asymmetricMatchers.ts
Expand Up @@ -7,7 +7,6 @@
*/

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

export class AsymmetricMatcher<T> {
protected sample: T;
Expand Down Expand Up @@ -162,31 +161,19 @@ 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 (
!hasProperty(other, property) ||
!equals(this.sample[property], other[property])
) {
return false;
}
for (const property in this.sample) {
if (
!hasProperty(other, property) ||
!equals(this.sample[property], other[property])
) {
result = false;
break;
}

return true;
}

return this.inverse ? !result : result;
}

toString() {
Expand Down

0 comments on commit e8b007b

Please sign in to comment.