Skip to content

Commit 23663fb

Browse files
committed
fix(no-useless-await): Fix false positive with expect.poll and resolves/rejects
Fixes #323
1 parent 6369932 commit 23663fb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/rules/no-useless-await.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,9 @@ runRuleTester('no-useless-await', rule, {
219219

220220
'await expect(page.locator(".my-element")).toBeVisible()',
221221
'await expect(page.locator(".my-element")).toHaveText("test")',
222+
223+
'await expect.poll(() => getSlowStorageValue(page, "key")).toBe("value")',
224+
'await expect(doSomething()).resolves.toThrow("No element found")',
225+
'await expect(doSomething()).rejects.toThrow("No element found")',
222226
],
223227
})

src/rules/no-useless-await.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Rule } from 'eslint'
22
import ESTree from 'estree'
3-
import { getStringValue, isPageMethod } from '../utils/ast'
3+
import { getStringValue, isIdentifier, isPageMethod } from '../utils/ast'
44
import { createRule } from '../utils/createRule'
55
import { parseFnCall } from '../utils/parseFnCall'
66

@@ -109,7 +109,14 @@ export default createRule({
109109

110110
// await expect(true).toBe(true)
111111
const call = parseFnCall(context, node)
112-
if (call?.type === 'expect' && expectMatchers.has(call.matcherName)) {
112+
if (
113+
call?.type === 'expect' &&
114+
!call.modifiers.some((modifier) =>
115+
isIdentifier(modifier, /^(resolves|rejects)$/),
116+
) &&
117+
!call.members.some((member) => isIdentifier(member, 'poll')) &&
118+
expectMatchers.has(call.matcherName)
119+
) {
113120
return fix(node.parent)
114121
}
115122
},

0 commit comments

Comments
 (0)