Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Not have keys" assertion seems unintuitive #254

Closed
aseemk opened this issue Apr 3, 2014 · 3 comments · Fixed by #313
Closed

"Not have keys" assertion seems unintuitive #254

aseemk opened this issue Apr 3, 2014 · 3 comments · Fixed by #313

Comments

@aseemk
Copy link

aseemk commented Apr 3, 2014

If I write:

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, and I wonder if you guys would be open to special-casing this negative assertion to be the more defensive one — and arguably more intuitive and useful as well.

@aseemk
Copy link
Author

aseemk commented Jun 23, 2014

Great suggestion from @dkillebrew for fixing this without breaking the existing behavior:

Automattic/expect.js#105 (comment)

In a nutshell, add any and all flags for have.keys, and deprecate calling have.keys without them.

@keithamus
Copy link
Member

@aseemk - thanks for the issue. Sorry for the late response on this one. You seem to have a good idea for a fix - would you like to make an attempt at a PR? If you get it merged you'll get a special spot in our super awesome hall of fame!

@aseemk
Copy link
Author

aseemk commented Dec 8, 2014

You guys rock! Thanks @cjqed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants