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
incorrectly failing
#919
Comments
Personally I would say that semantically both of those seem like they should fail. One of the best things about Chai is it's human readability. To which both of these seem wrong. Given the examples above expect({a: 1, b: 2, c: 3}).to.have.keys('a', 'b'); // I would've expected to pass I would have expected to pass. To have the behaviour that I guess is the correct behaviour for that assertion (failing) I would expect something like expect({a: 1, b: 2, c: 3}).to.have.exact.keys('a', 'b');
// or
expect({a: 1, b: 2, c: 3}).to.only.have.keys('a', 'b'); Semantically I would expect both of these to fail when reading them. Likewise, the second one, semantically, I think should fail, |
@leggsimon Yeah, we have a bit of a problem right now with some of our list-like assertions. The default behavior is inconsistent among them, and there's also inconsistency in how they interact with the Right now, the problem described in this issue is considered a bug because it doesn't match the currently documented behavior of In the long term, a major change needs to be made to bring all of these related assertions into a state of consistency. I agree with you that given the two options below, the first seems more semantic:
Unfortunately, the second option was originally chosen, and to change it to the first option now at this point in the project will be an enormous breaking change. Given the current state of things, it'll be much smaller of a breaking change to bring all of the assertions in-line with the second option than the first option. Even though the first option is better, I don't know if it's better enough to justify the degree of breakage that it'll cause in a project of Chai's maturity. Never an easy decision. |
Because of this line (I presume), the following tests both fail:
The second test is incorrectly failing; it should pass right away on the basis that the target and given values don't have the same number of keys, which is a requirement when the
contains
flag isn't set.The text was updated successfully, but these errors were encountered: