Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2524,10 +2524,6 @@ function assertKeys(keys) {
});
}

if (!keys.length) {
throw new AssertionError(flagMsg + 'keys required', undefined, ssfi);
}

let len = keys.length,
any = flag(this, 'any'),
all = flag(this, 'all'),
Expand All @@ -2538,6 +2534,12 @@ function assertKeys(keys) {
all = true;
}

// Fix for PR #1384: Allow empty keys only if we are checking 'all'.
// 'any' keys requires at least one key to be checked against.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Fix for PR #1384: Allow empty keys only if we are checking 'all'.
// 'any' keys requires at least one key to be checked against.
// Allow empty keys if we're checking `all` since you can assert it has _no keys_
// For `any`, we need at least one key.

since the PR isn't relevant info anymore at this point (its a feature rather than a bug)

if (!keys.length && !all) {
throw new AssertionError(flagMsg + 'keys required', undefined, ssfi);
}

// Has any
if (any) {
ok = expected.some(function (expectedKey) {
Expand Down
Loading