diff --git a/lib/rules/await-async-events.ts b/lib/rules/await-async-events.ts index 0d2a3174..0e3a9dc3 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, @@ -250,6 +251,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 ' diff --git a/tests/lib/rules/await-async-events.test.ts b/tests/lib/rules/await-async-events.test.ts index fe855fac..3aa400bd 100644 --- a/tests/lib/rules/await-async-events.test.ts +++ b/tests/lib/rules/await-async-events.test.ts @@ -1460,5 +1460,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' }, + }, + ], + }, ], });