Skip to content

noPlaywrightUselessAwait (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"complexity": {
"noPlaywrightUselessAwait": "error"
}
}
}
}

Disallow unnecessary await for Playwright methods that don’t return promises.

Some Playwright methods are frequently, yet incorrectly, awaited when they return synchronous values. This includes locator methods, which return locators (not promises), and synchronous expect matchers.

await page.locator('.my-element');
code-block.js:1:1 lint/complexity/noPlaywrightUselessAwait  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Unnecessary await expression.

> 1 │ await page.locator('.my-element');
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ This method does not return a Promise.

ℹ Safe fix: Remove unnecessary await

1 │ await·page.locator('.my-element');
│ ------
await page.getByRole('button');
code-block.js:1:1 lint/complexity/noPlaywrightUselessAwait  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Unnecessary await expression.

> 1 │ await page.getByRole('button');
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ This method does not return a Promise.

ℹ Safe fix: Remove unnecessary await

1 │ await·page.getByRole('button');
│ ------
await expect(1).toBe(1);
code-block.js:1:1 lint/complexity/noPlaywrightUselessAwait  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Unnecessary await expression.

> 1 │ await expect(1).toBe(1);
│ ^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ This method does not return a Promise.

ℹ Safe fix: Remove unnecessary await

1 │ await·expect(1).toBe(1);
│ ------
page.locator('.my-element');
await page.locator('.my-element').click();
page.getByRole('button');
await page.getByRole('button').click();
expect(1).toBe(1);
await expect(page.locator('.foo')).toBeVisible();