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.
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 https://github.com/chaijs/chai/issues/919#issuecomment-275938769 and #881, with the former mentioning .only. This is high on my list to circle back to after 4.0 is released.
Any update on this?
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.
Most helpful comment
Any update on this?