testing-library / testing-library/eslint-plugin-testing-library

New rule `no-sync-act`: discourages sync usage of `act`

Open
#915 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

new rule
Dominant language
TypeScript
Stars
1.1k
Forks
168
Avg merge
15h 44m
Merged PRs (30d)
14

Description

Name for new rule

no-sync-act

Description of the new rule

As per https://react.dev/reference/react/act#await-act-async-actfn
sync usage of act is discouraged:

We recommend using act with await and an async function. Although the sync version works in many cases, it doesn’t work in all cases and due to the way React schedules updates internally, it’s difficult to predict when you can use the sync version.

We will deprecate and remove the sync version in the future.

Testing Library feature

act

Testing Library framework(s)

React

What category of rule is this?

Warns about a potential error

Optional: other category of rule

No response

Code examples

The new rule would fail on

act(() => {
await act(() => {
act(async () => {

and pass on

await act(async () => {
Anything else?

No response

Do you want to submit a pull request to make the new rule?

No

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files or tests are named. Locate existing act-related rules and their React rule tests, then use the issue's examples to define the warning for synchronous act usage and the accepted awaited async form.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
testing-qa, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.