Skip to content

Commit 097705f

Browse files
committed
fix: await-async-queries has false positive with optional chaining
Closes testing-library#882
1 parent 8905e0c commit 097705f

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/node-utils/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ function getRootExpression(
278278
return parent.expressions[parent.expressions.length - 1] === expression
279279
? getRootExpression(parent)
280280
: expression;
281+
282+
case AST_NODE_TYPES.ChainExpression:
283+
return getRootExpression(parent);
284+
281285
default:
282286
return expression;
283287
}

tests/lib/rules/await-async-queries.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ ruleTester.run(RULE_NAME, rule, {
9393
// async screen queries declaration are valid
9494
...createTestCase((query) => `await screen.${query}('foo')`),
9595

96+
// async queries with optional chaining are valid
97+
...createTestCase((query) => `await screen?.${query}('foo')`),
98+
9699
// async @marko/testing-library screen queries declaration are valid
97100
...createTestCase((query) => `await screen.${query}('foo')`, {
98101
testingFramework: '@marko/testing-library',

0 commit comments

Comments
 (0)