eslint-plugin-testing-library icon indicating copy to clipboard operation
eslint-plugin-testing-library copied to clipboard

await-async-event adds async and await in forEach loop

Open fa93hws opened this issue 2 years ago • 3 comments

Have you read the Troubleshooting section?

Yes

Plugin version

v6.1.2

ESLint version

v8.45.0

Node.js version

20.8.1

package manager and version

yarn 1.22.19

Operating system

macos 13.6.1

Bug description

async and await doesn't work for forEach loop. I think we should give up autofixing this issue.

Steps to reproduce

foo.forEach(() => {
  userEvent.click();
});

After autofix, it becomes

foo.forEach(async () => {
  await userEvent.click();
});

Error output/screenshots

No response

ESLint configuration

{ ... "testing-library/await-async-event": "error", }

Rule(s) affected

await-async-event

Anything else?

No response

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

Yes

fa93hws avatar Nov 13 '23 06:11 fa93hws

Hi @fa93hws, thanks for reporting! I believe this is still relevant.

Belco90 avatar Jun 11 '25 08:06 Belco90

~~I could not reproduce this issue. When I run the following code, the autofix does not add async/await to the forEach callback:~~

const foo = [];
foo.forEach(() => {
  userEvent.click();
});

Sorry, my mistake 😂 The error is already being detected as-is.

Plugin version: v7.5.2

y-hsgw avatar Jun 13 '25 12:06 y-hsgw

I could not reproduce this issue. When I run the following code, the autofix does not add async/await to the forEach callback:

const foo = [];
foo.forEach(() => {
  userEvent.click();
});

Plugin version: v7.5.2

Let's add a test for this scenario to verify is not a problem anymore, so we can close this issue.

Belco90 avatar Jun 13 '25 15:06 Belco90

:tada: This issue has been resolved in version 7.9.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Sep 24 '25 05:09 github-actions[bot]