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

Document best practices for test assertions #646

Open
zeke opened this issue Dec 29, 2015 · 4 comments
Open

Document best practices for test assertions #646

zeke opened this issue Dec 29, 2015 · 4 comments

Comments

@zeke
Copy link

@zeke zeke commented Dec 29, 2015

There's an issue on enzyme enzymejs/enzyme#97 about strengthening the assertion styles to avoid false positives:

A great first task would be removing this rule override, and fixing our tests and docs to use, for example, .to.equal(true) instead of .to.be.true

The issue mentions that the to.be.true style violates this styleguide, but I wasn't able to find any content here that alludes to this.

@Ensive
Copy link
Contributor

@Ensive Ensive commented Feb 27, 2019

@ljharb
How actual this issue is?
Do you think we need to add something like:

Do not use to.be.true, etc. in your tests, but use .to.equal(true)

Shall we put it within Testing section?

@ljharb
Copy link
Collaborator

@ljharb ljharb commented Feb 27, 2019

Yes, but specifically, a section on never using "noop" matchers - ie, anything that doesn't end in a function call - because the cost of a typo is a silent passing test. In other words, expect(x).to.be.yogurt; will merrily pass, whereas expect(x).to.be.yogurt() will correctly throw, failing your test.

@zeke
Copy link
Author

@zeke zeke commented Feb 28, 2019

Thanks for following up on this, @ljharb 👍

Since opening this issue (over three years ago!), the standard linter has been updated to no longer allow expressions like to.be.true, which has protected me from accidentally using that assertion style in projects.

@ljharb
Copy link
Collaborator

@ljharb ljharb commented Feb 28, 2019

@zeke this config has protected you from that for 3.5 years.

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.