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.

new rule: no-side-effects-wait-for

See original GitHub issue

Following the proposed for Kent at his post (https://kentcdodds.com/blog/common-mistakes-with-react-testing-library). I would like to suggest a new rule that detects side effects inside a wait-for:

❌ // wrong
await waitFor(() => {
  fireEvent.click(a)
  expect(b).toEqual('b')
})
✅ // correct
fireEvent.click(a)
await waitFor(() => expect(b).toEqual('b'))

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Belco90commented, Jun 22, 2020

Awesome, thanks for your help 💪

1reaction
renatoagdscommented, Jun 22, 2020

Just to update! I’m finishing #133 this week and will start work on this one 🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

EsLint - Suppress "Do not use 'new' for side effects"
Disallow new For Side Effects ( no-new ). The goal of using new with a constructor is typically to create an object of...
Read more >
Testing-library: avoid these mistakes in async tests
As waitFor is non-deterministic and you cannot say for sure how many times it will be called, you should never run side-effects inside...
Read more >
eslint-plugin-testing-library - npm
Supported Rules ; no-wait-for-side-effects, Disallow the use of side effects in waitFor ; no-wait-for-snapshot, Ensures no snapshot is generated ...
Read more >
testing library: side-effects and `waitfor` - code-comments
(Note: This particular component uses a reducer pattern within a Context API. On a dismiss action, regardless of whether or not the consumer...
Read more >
React Testing Library best practices | Ben Ilegbodu
Instead the best practice is to move these sorts of side-effects outside of the waitFor callback, and only put assertions within it. The...
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