Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/rules/await-async-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createTestingLibraryRule } from '../create-testing-library-rule';
import {
findClosestCallExpressionNode,
findClosestFunctionExpressionNode,
getDeepestIdentifierNode,
getFunctionName,
getInnermostReturningFunction,
getVariableReferences,
Expand Down Expand Up @@ -153,6 +154,13 @@ export default createTestingLibraryRule<Options, MessageIds>({
findClosestFunctionExpressionNode(node);

if (functionExpression) {
const deepestCalleeIdentifier = getDeepestIdentifierNode(
functionExpression.parent
);
if (deepestCalleeIdentifier?.name === 'forEach') {
return null;
}

const memberExpressionFixer = fixer.insertTextBefore(
node.parent,
'await '
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/await-async-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
},
],
},
],
});