Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await-async-events produces false-positives #881

Closed
kripod opened this issue Feb 21, 2024 · 3 comments · Fixed by #895
Closed

await-async-events produces false-positives #881

kripod opened this issue Feb 21, 2024 · 3 comments · Fixed by #895
Labels
bug Something isn't working released

Comments

@kripod
Copy link

kripod commented Feb 21, 2024

Have you read the Troubleshooting section?

Yes

Plugin version

v6.2.0

ESLint version

v8.56.0

Node.js version

v20.10.0

package manager and version

pnpm 7.33.7

Operating system

macOS Sonoma, version 14.3.1

Bug description

The userEvent.setup() method is treated as if it were returning a Promise when wrapped by an arrow function expression.

Steps to reproduce

While exposing a getUser wrapper around userEvent.setup for reuse:

export const getUser = () =>
  userEvent.setup({
    advanceTimers: (msToRun: number) => jest.advanceTimersByTime(msToRun),
  });

Usages like:

const user = getUser();

Produce a false-positive error as follows:

error  Promise returned from `getUser` wrapper over async event method must be handled  testing-library/await-async-events

However, userEvent.setup isn‘t an async method, so there isn‘t anything to await.

Error output/screenshots

No response

ESLint configuration

{
  "extends": ["plugin:testing-library/react"]
}

or

{
  "plugins": ["testing-library"],
  "rules": {
    "testing-library/await-async-events": "error"
  }
}

Rule(s) affected

testing-library/await-async-events

Anything else?

No response

Do you want to submit a pull request to fix this bug?

No

@kripod kripod added bug Something isn't working triage Pending to be triaged by a maintainer labels Feb 21, 2024
@JulianG-TW
Copy link

Just in case it helps.

If I change getUser to

export const getUser = () => {
  const user = userEvent.setup({
    advanceTimers: (msToRun: number) => jest.advanceTimersByTime(msToRun),
  });
  return user;
}

...then the false-positive error is gone.

@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label Mar 4, 2024
@Belco90
Copy link
Member

Belco90 commented Mar 4, 2024

Thanks for reporting @kripod

Copy link

🎉 This issue has been resolved in version 6.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
3 participants