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

[expect-expect] Option to enforce the last statement of a test to be an assertion #1338

Open
CreativeTechGuy opened this issue Feb 1, 2023 · 3 comments

Comments

@CreativeTechGuy
Copy link

The expect-expect rule works great for identifying a test that doesn't have any assertions, but it doesn't work for identifying halfway-complete tests. Often more complex test cases (such as JSDOM tests) will have multiple assertions, usually before something has occurred to assert the base state is correct, then perform an action, and then assert that the values have changed as expected. I have found a few times where I'll be writing a test and get distracted halfway through and forget to finish the second half of the test. Code coverage looks good since all of the actions were performed, but the test was missing the critical assertions at the end.

In almost every test, there should be an assertion as the last statement. The only case where I can think of that not being true is when the assertions are inside of callback function, but that can be avoided by putting expect.assertions(number) as the last line.

Since it seems like a generally useful option which aligns with the spirit of this rule, I wanted to suggest this as a new feature.

@danielnixon
Copy link

Code coverage looks good since all of the actions were performed, but the test was missing the critical assertions at the end.

Unhelpful drive-by suggestion: mutation testing can help on this front, e.g. https://stryker-mutator.io/

@SimenB
Copy link
Member

SimenB commented Feb 18, 2023

@G-Rath thoughts on this? I think it sounds like a good idea - not sure if it should be an option on expect-expect or a separate rule

@G-Rath
Copy link
Collaborator

G-Rath commented Feb 19, 2023

@SimenB yeah it makes sense to me, and probably as an option to expect-expect 🤔

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

No branches or pull requests

4 participants