Skip to content

Commit

Permalink
Address a number of issues with array-like "to satisfy".
Browse files Browse the repository at this point in the history
This commit fixes key checking issues when satisfying array-like.
First, when a non-numerical property comparison is forced by it
being supplied on the RHS this should work. Secondly, in the case
of a non-numerical array-like there was an issue calculating how
many outstanding keys there were when enumerability differences
came into the picture. Fixes regression tests added in f44439d.
  • Loading branch information
alexjeffburke committed Dec 29, 2018
1 parent b34a3bf commit d7e5f5f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/assertions.js
Expand Up @@ -1499,24 +1499,28 @@ module.exports = expect => {
expect.promise(() => {
// create subject key presence object
const remainingKeysInSubject = {};
subjectType.getKeys(subject).forEach(key => {
subjectKeys.forEach(key => {
remainingKeysInSubject[key] = 1; // present in subject
});
// discard or mark missing each previously seen value key
valueKeys.forEach(key => {
if (!remainingKeysInSubject[key]) {
if (
!remainingKeysInSubject[key] &&
(utils.numericalRegExp.test(key) || expect.flags.exhaustively)
) {
remainingKeysInSubject[key] = 2; // present in value
} else {
delete remainingKeysInSubject[key];
}
});
// filter outstanding keys which should not lead to an error
// check whether there are any outstanding keys we cannot account for
const outstandingKeys = Object.keys(remainingKeysInSubject).filter(
key =>
utils.numericalRegExp.test(key) ||
typeof key === 'symbol' ||
typeof subjectType.valueForKey(subject, key) !== 'undefined' ||
remainingKeysInSubject[key] === 2
(typeof subjectType.valueForKey(subject, key) !== 'undefined' &&
// key was only in the value
remainingKeysInSubject[key] === 2)
);
// key checking succeeds with no outstanding keys
expect(outstandingKeys.length === 0, 'to be truthy');
Expand Down

0 comments on commit d7e5f5f

Please sign in to comment.