[prefer-expect-assertions]: ensure expect.assertions is used when an expect is found to be within a loop
See original GitHub issueIt would be nice to have a lint rule that enforced a length check or use of expect.assertions when an expect call is found inside a loop.
for example:
for(let thing in things) {
expect(thing).toBe("2");
}
would report an error
but this would not:
expect.assertions(4);
for(let thing in things) {
expect(thing).toBe("2");
}
nor would this:
expect(things).toHaveLength(4);
for(let thing in things) {
expect(thing).toBe("2");
}
Main goal here is to prevent false positive tests if things
is an empty list.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Necessary to use expect.assertions() if you're awaiting any ...
Using expect.assertions at the start of the test ensures that if the assertions inside the catch don't run, we get a failure.
Read more >Expect - Jest
expect.assertions(number) verifies that a certain number of assertions are called during a test. This is often useful when testing asynchronous ...
Read more >Eslint-plugin-jest NPM
Rules ; expect-expect, Enforce assertion to be made in a test body, recommended ; max-expects, Enforces a maximum number assertion calls in a...
Read more >Retry-ability - Cypress Documentation
What you'll learn How Cypress retries commands and assertions When commands ... Thus cy.get and cy.find() have to be smarter and expect the...
Read more >Unit Testing in NodeJS - Basics with Examples
1) Setup testing framework with Jest; 2) Writing assertion style; ... let expected = "not a number" // Use forEach loop to test...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have implemented an option for native loops in #1013
🎉 This issue has been resolved in version 25.4.0 🎉
The release is available on:
Your semantic-release bot 📦🚀