new rule: no-side-effects-wait-for
See original GitHub issueFollowing 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:
- Created 3 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top 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 >
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 Free
Top 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
Awesome, thanks for your help 💪
Just to update! I’m finishing #133 this week and will start work on this one 🚀