Skip to content

Commit

Permalink
Merge 5561915 into c1ed242
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Aug 20, 2022
2 parents c1ed242 + 5561915 commit d179a9e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/assertions.js
Expand Up @@ -1986,7 +1986,8 @@ module.exports = (expect) => {
let forceExhaustivelyComparison = false;
uniqueKeys.forEach((key, index) => {
const subjectHasKey = subjectType.hasKey(subject, key);
const valueKey = valueType.hasKey(value, key, true)
const valueHasKey = valueType.hasKey(value, key, true);
const valueKey = valueHasKey
? valueType.valueForKey(value, key)
: undefined;
const valueKeyType = expect.findTypeOf(valueKey);
Expand All @@ -1995,7 +1996,7 @@ module.exports = (expect) => {
// ensure value only expect.it key is marked missing
forceExhaustivelyComparison = true;
}
} else if (subjectHasKey && typeof valueKey === 'undefined') {
} else if (subjectHasKey && !valueHasKey) {
// ignore subject only keys unless we are being exhaustive
return;
}
Expand Down
27 changes: 24 additions & 3 deletions test/assertions/to-satisfy.spec.js
Expand Up @@ -1747,9 +1747,30 @@ describe('to satisfy assertion', () => {
});
});

it('should assert missing properties with undefined in the RHS object', () => {
expect({ foo: 123 }, 'to satisfy', {
bar: undefined,
describe('when asserting missing properties with undefined in the RHS object', () => {
describe('when the property is missing', () => {
it('should succeed', () => {
expect({ foo: 123 }, 'to satisfy', {
bar: undefined,
});
});
});

describe('when the property is present', () => {
it('should fail with an error', () => {
expect(
() =>
expect({ foo: 123 }, 'to satisfy', {
foo: undefined,
}),
'to throw',
'expected { foo: 123 } to satisfy { foo: undefined }\n' +
'\n' +
'{\n' +
' foo: 123 // should equal undefined\n' +
'}'
);
});
});
});

Expand Down

0 comments on commit d179a9e

Please sign in to comment.