Automattic / Automattic/expect.js

"Not have keys" assertion seems unintuitive

Open
#105 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.1k
Forks
207
PR merge metrics
No merged PRs in 30d

Description

If I write:

``` js
expect(obj).to.not.have.keys('password', 'secret', 'token');
```

You'd think it would fail if the object had any of those keys. But it actually passes even if it has one or more of them... as long as it doesn't have _all_ of them.

I get why this is: because `expect(obj).to.have.keys(keys)` asserts that _all_ of the given keys are there, so negating that means negating "all" means "none or some".

But this bit me pretty hard just now, so I wonder if you'd be open to special-casing this negative assertion to be the more defensive and, arguably, intuitive and useful.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the existing `have.keys` assertion and its negated behavior described in the issue, then read the six-comment discussion for the project's decision. Done means the maintainers agree on the intended negative-assertion semantics and the behavior is covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.