-
Notifications
You must be signed in to change notification settings - Fork 117
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
.toExcludeKeys not working as expected #180
Comments
I would read it as
So the fact that the object only excludes key 'b' means the assertion fails. It makes sense to me. |
I do see the value in having both toExcludeAnyKeys and toExcludeAllKeys. Perhaps it's worth adding the "any" version? |
The issue, though, is that the code currently implements |
And yeah, via the docs:
Which should be interpreted to mean: for all provided keys, there exist none which are properties of the object. This is definitely not satisfied by the test posted by @5c077yP |
The tests are the source of truth here. The documentation says "does not contain any of the provided keys" - so it seems the documentation needs updating, to something like "is missing all of the provided keys". If you want |
But it seems |
I would see |
That currently isn't the case: Line 532 in 5ede172
Also, did you mean:
? |
No, I didn't realize the alias already existed. Given that, I think we need |
Ah, right sorry. Too many double negatives. 😂 I was thinking "passes" not "throws" Seems I don't get the naming. For me:
and
|
I think we're using conflicting forms of "any" and "all" here. To me, "toExcludeAny" means that if any of the keys exist on the object, it throws - if none exist, it passes. In other words, if any of the given keys exists, it's violating "excluded". To me, "toExcludeAll" means that it only throws when all of the given keys are not excluded. Either way the naming is confusing, but https://github.com/mjackson/expect/blob/master/modules/__tests__/toExcludeKeys-test.js#L28-L38 implements "it only throws when all excluded keys exist" - and what we want to add is "it throws when any excluded key exists". |
Could be read as:
This should pass, because [ a: 0, b: 0 ] excludes the key
Could be read as:
Should throw (not pass), because [ a: 0, c: 0 ] only excludes |
@wilkesreid Right, that's in agreement with what I was saying, but not in agreement with @ljharb's comment just before yours, which gives the opposite definition IMO, the behavior should be the same as in the list processing functions |
I agree - all/every and any/some should mean those things - but although the wording of the documentation for "toExcludeKeys" is confusing, it does not in fact inherently conform to either concept "all" or "any" solely by virtue of its name. |
@ljharb For sure :) I was just trying to sort out how we're defining |
Hey,
thanks for this great library.
I just came across
.toExcludeKeys
. And for me it feels that something is wrong here. The docs say:Which sounds to me, if there is at least one key in the provided
keys
which is contained in the givenobject
, it should fail.But then on the other side there is even a test like this
That looks more like, there needs to be at least on key in
keys
which is not inobject
and then it's fine.Thanks.
The text was updated successfully, but these errors were encountered: