question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[prefer-expect-assertions]: ensure expect.assertions is used when an expect is found to be within a loop

See original GitHub issue

It 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:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
G-Rathcommented, Dec 30, 2021

Have implemented an option for native loops in #1013

0reactions
github-actions[bot]commented, Jan 15, 2022

🎉 This issue has been resolved in version 25.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found