From 8cf41e0884167a8a40b20fb5cefe673bd4492c19 Mon Sep 17 00:00:00 2001 From: Hasegawa-Yukihiro Date: Thu, 4 Sep 2025 00:05:31 +0900 Subject: [PATCH 1/2] feat: add support for handling 'forEach' in async event method detection --- lib/rules/await-async-events.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/rules/await-async-events.ts b/lib/rules/await-async-events.ts index 7ac69ede..6310c327 100644 --- a/lib/rules/await-async-events.ts +++ b/lib/rules/await-async-events.ts @@ -4,6 +4,7 @@ import { createTestingLibraryRule } from '../create-testing-library-rule'; import { findClosestCallExpressionNode, findClosestFunctionExpressionNode, + getDeepestIdentifierNode, getFunctionName, getInnermostReturningFunction, getVariableReferences, @@ -153,6 +154,13 @@ export default createTestingLibraryRule({ findClosestFunctionExpressionNode(node); if (functionExpression) { + const deepestCalleeIdentifier = getDeepestIdentifierNode( + functionExpression.parent + ); + if (deepestCalleeIdentifier?.name === 'forEach') { + return null; + } + const memberExpressionFixer = fixer.insertTextBefore( node.parent, 'await ' From 5d0ec0d0881f3a74cd149a0608899900d6cfede1 Mon Sep 17 00:00:00 2001 From: Hasegawa-Yukihiro Date: Thu, 4 Sep 2025 00:06:24 +0900 Subject: [PATCH 2/2] test: add test case for handling 'forEach' with userEvent clicks --- tests/lib/rules/await-async-events.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/lib/rules/await-async-events.test.ts b/tests/lib/rules/await-async-events.test.ts index afa4495a..aeef9df0 100644 --- a/tests/lib/rules/await-async-events.test.ts +++ b/tests/lib/rules/await-async-events.test.ts @@ -1269,5 +1269,24 @@ ruleTester.run(RULE_NAME, rule, { }) `, }, + { + code: ` + import userEvent from '${USER_EVENT_ASYNC_FRAMEWORKS[0]}' + test('setup method called is valid', () => { + const foo = []; + foo.forEach(() => { + userEvent.click(); + }); + }) + `, + errors: [ + { + line: 6, + column: 6, + messageId: 'awaitAsyncEvent', + data: { name: 'click' }, + }, + ], + }, ], });