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.

Make sure `no-unnecessary-act` detects unnecessary `act` called before the `render` method

See original GitHub issue

What rule do you want to change?

no-unnecessary-act

Does this change cause the rule to produce more or fewer warnings?

More warnings

How will the change be implemented?

I don’t have a plan to implement the change yet. The idea is to improve the rule no-unnecessary-act so it can detect unnecessary act which are called before a render. https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/rules/no-unnecessary-act.md Those unnecessary make the codebase noisy.

Example code

act(() => {
  someSetupMethod();
});

render(<Example />);

How does the current rule affect the code?

This unnecessary act is not detected

How will the new rule affect the code?

This unnecessary act is detected

Anything else?

No response

Do you want to submit a pull request to change the rule?

Yes, but need help

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fabiendemcommented, Apr 20, 2022

Rules must not depend on each other, so we have to assume this scenario is possible.

yeah definitely

LGTM! So this rule would report acts for the current criteria OR for acts called before a render within the test block (ignoring them if no render is found).

yeah seems legit

1reaction
fabiendemcommented, Feb 18, 2022

Thank you 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-testing-library/no-unnecessary-act.md at main
Disallow wrapping Testing Library utils or empty callbacks in act ( testing-library/no-unnecessary-act ). This rule is enabled in the following configs: ...
Read more >
React Testing Library and the “not wrapped in act” Errors
I recently upgraded React and React testing library. Very happy about the upgrade. But I start to see test errors like this: In...
Read more >
How To Test a React App with Jest and React Testing Library
Inside the function, there is a render method that React Testing Library provides to render your component into the DOM. With the component ......
Read more >
"React has detected a change in the order of Hooks" but ...
That causes react to treat the hook calls inside the function as part of ... and not being called before because of conditional...
Read more >
You Probably Don't Need act() in Your React Tests
In most cases, react-testing-library makes wrapping test code in act() unnecessary. Furthermore, doing so might cause additional problems.
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