diff --git a/src/rules/no-useless-await.test.ts b/src/rules/no-useless-await.test.ts index 0a0b7ae..eb88d52 100644 --- a/src/rules/no-useless-await.test.ts +++ b/src/rules/no-useless-await.test.ts @@ -219,5 +219,9 @@ runRuleTester('no-useless-await', rule, { 'await expect(page.locator(".my-element")).toBeVisible()', 'await expect(page.locator(".my-element")).toHaveText("test")', + + 'await expect.poll(() => getSlowStorageValue(page, "key")).toBe("value")', + 'await expect(doSomething()).resolves.toThrow("No element found")', + 'await expect(doSomething()).rejects.toThrow("No element found")', ], }) diff --git a/src/rules/no-useless-await.ts b/src/rules/no-useless-await.ts index 8231128..b66d7d7 100644 --- a/src/rules/no-useless-await.ts +++ b/src/rules/no-useless-await.ts @@ -1,6 +1,6 @@ import { Rule } from 'eslint' import ESTree from 'estree' -import { getStringValue, isPageMethod } from '../utils/ast' +import { getStringValue, isIdentifier, isPageMethod } from '../utils/ast' import { createRule } from '../utils/createRule' import { parseFnCall } from '../utils/parseFnCall' @@ -109,7 +109,14 @@ export default createRule({ // await expect(true).toBe(true) const call = parseFnCall(context, node) - if (call?.type === 'expect' && expectMatchers.has(call.matcherName)) { + if ( + call?.type === 'expect' && + !call.modifiers.some((modifier) => + isIdentifier(modifier, /^(resolves|rejects)$/), + ) && + !call.members.some((member) => isIdentifier(member, 'poll')) && + expectMatchers.has(call.matcherName) + ) { return fix(node.parent) } },