-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
'truthy' and 'falsy' should be chainable properties. #235
Comments
I'm happy to submit a PR if people are amenable to the idea. |
This seems redundant for core as |
Consider this fairly common scenario: Some API's return a result object which may or may not have a property var result = someActionThatShouldProduceAnError();
expect(result.error).to.be.ok; That is potentially confusing to someone who isn't familiar with chai. The following is easier to understand. expect(result.error).to.be.truthy If you google "javascript ok" vs. "javascript truthy", I think it shows that Chai is full of redundant syntax, so rejection on that basis seems arbitrary.
I could be persuaded to give up on |
Realize this is closed, but giving this a 👍 because I also think that "truthy"/"falsy" is more clear than "ok". |
OMG +1 for this. just ran into this as well. We've been using truthy and falsy throughout our tests and just discovered that they're not actually passing or failing. And chai doesn't complain at |
@jamestalmage came exactly to comment on the same. On my code: expect(res.error).to.be.not.ok; Where this would be a lot more clear: expect(res.error).to.be.falsy; |
@logicalparadox +1 on the intuitiveness of |
+1 we've had a lot of confusion on this in our codebase |
Accidentally using undefined terminating properties leads to the expect check not working as expected. For example, expect(foo).to.be.falsy results in a no-op that does not perform any check and is probably not what the author intended. See chaijs/chai#235 for a discussion of "truthy" and "falsy", including examples of people that have run into this: chaijs/chai#235 (comment)
Accidentally using undefined terminating properties leads to the expect check not working as expected. For example, expect(foo).to.be.falsy results in a no-op that does not perform any check and is probably not what the author intended. See chaijs/chai#235 for a discussion of "truthy" and "falsy", including examples of people that have run into this: chaijs/chai#235 (comment)
Also bitten by this. If someone actually finds a plugin/workaround for this, please let the rest of us know? Thanks! |
I would also like to ask for this feature and reopen the issue. Writing |
@logicalparadox there are several instances of assertion aliases already in Chai. This seems a pretty reasonable alias. I have to google "chaijs truthy" (or "chaijs falsy") every time. On a related note: "ok" is very unclear. "ok" literally means "all right" (as in, "no problems"), so one would reasonably see "ok" and think "doesn't throw". |
Especially since the description for
ok
actually uses the word truthy.The text was updated successfully, but these errors were encountered: