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

expect(...).to.only.have.keys(...) #963

Closed
danthegoodman opened this issue May 4, 2017 · 3 comments
Closed

expect(...).to.only.have.keys(...) #963

danthegoodman opened this issue May 4, 2017 · 3 comments

Comments

@danthegoodman
Copy link

I find the language chain to.have.all.keys difficult to understand. The docs say this means "to have all and only all of the passed in keys", but when I read that chain linguistically, I think that it means "to have all of the passed in keys but may have more keys not listed".

My request is to add a chain word of only. Here are some examples of how I think it could be used:

let oX = {x:1}
let oXY = {x:1, y:2}

expect(oX).to.contain.all.keys('x')       // pass
expect(oX).to.only.contain.all.keys('x')  // pass
expect(oX).to.only.have.keys('x')         // pass

expect(oXY).to.contain.all.keys('x')      // pass
expect(oXY).to.only.contain.all.keys('x') // fail
expect(oXY).to.only.have.keys('x')        // fail

The introduction of the chain word only could impact some other functions, such as members.

This is highly related to #956, but I felt it this could be addressed separately from the other requests in that issue.

@meeber
Copy link
Contributor

meeber commented May 4, 2017

Yeah as I mentioned in #956, we definitely have work to do with the .keys assertion and .any/.all flags. The problems are discussed more in #919 (comment) and #881, with the former mentioning .only. This is high on my list to circle back to after 4.0 is released.

@svicalifornia
Copy link

Any update on this?

@keithamus
Copy link
Member

keithamus commented Jun 13, 2018

Thanks @danthegoodman for this issue!

We've got some ideas on how to address this properly in our Roadmap https://github.com/chaijs/chai/projects/2! We'll be releasing chai 5 soon, but for now I'll close this issue because it is tracked on our roadmap.

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

No branches or pull requests

4 participants