Catch Missing `await` Calls in Playwright Tests with ESLint
Debbie O'Brien

Debbie O'Brien @debs_obrien

About: Principal Technical Program Manager at Microsoft, speaker, writer, teacher, open source contributor, playwright, vue, nuxt, react

Location:
Spain
Joined:
Aug 15, 2019

Catch Missing `await` Calls in Playwright Tests with ESLint

Publish Date: Apr 16
31 9

Have you ever run a Playwright test that just... didn’t behave as expected? Maybe it failed randomly. Maybe it passed locally but broke in CI. The culprit? Often—it’s just a missing await.

It’s one of the easiest mistakes to make in async code, and in testing, it can lead to race conditions and flaky results.

The Problem: A Missing await Can Break Your Test

Let’s look at a simple example. We click a button and expect a modal to appear:

await page.getByRole('button', { name: 'Submit' }).click();
expect(page.getByRole('dialog')).toBeVisible(); // ❌ Missing 'await'
Enter fullscreen mode Exit fullscreen mode

The expect() call returns a promise, but we didn’t await it, so Playwright moves on before it finishes. Sometimes the modal appears in time. Sometimes it doesn't. Result? Flaky test.

What’s worse? VS Code won’t warn you about this by default.

The Fix: Let ESLint Catch Floating Promises

Luckily, we can set up a TypeScript ESLint rule to help us catch these mistakes automatically. The rule is called @typescript-eslint/no-floating-promises, and it highlights any promise that isn't properly handled.

Here’s how to set it up:

1. Install ESLint and TypeScript Support

If you haven’t already (ensure you have ESLint v9+ and TypeScript):

npm install --save-dev eslint typescript-eslint typescript
Enter fullscreen mode Exit fullscreen mode

2. Create tsconfig.json (If Needed)

The @typescript-eslint/no-floating-promises rule requires type information. Ensure you have a tsconfig.json file in your project root. If not, create a basic one:

// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true // Important for linting without compiling
    // Add other options relevant to your project (e.g., "jsx": "react-jsx")
  },
  "include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.mjs"],
  "exclude": ["node_modules"]
}
Enter fullscreen mode Exit fullscreen mode

3. Configure ESLint in eslint.config.mjs

Create or update eslint.config.mjs in your project root to enable type-aware linting:

// eslint.config.mjs
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
  eslint.configs.recommended,
  // Use recommendedTypeChecked for rules requiring type information
  ...tseslint.configs.recommendedTypeChecked,
  {
    // Configure language options for type checking
    languageOptions: {
      parserOptions: {
        project: true, // Use the tsconfig.json in the root
      },
    },
    rules: {
      '@typescript-eslint/no-floating-promises': 'error',
      // Other rules can be added here
    },
  },
  {
    // Optionally, ignore specific files/folders
    ignores: ['dist/**', 'node_modules/**', 'playwright.config.ts'], // Adjust as needed
  }
);
Enter fullscreen mode Exit fullscreen mode

ESLint v9+ uses a new configuration file format. Checkout the ESLint documentation for more details.

4. Install the ESLint VS Code Extension

To see the errors directly in your editor, make sure you have the official ESLint extension installed in VS Code. Search for dbaeumer.vscode-eslint in the Extensions view and click Install.

Tip: If ESLint warnings don't appear immediately after configuration, try reloading the VS Code window (Command Palette: Developer: Reload Window).

The Result: Instant Feedback in VS Code

Now, when you forget an await, VS Code will show a squiggly line under the issue before you even run the test.

ESLint Warning in vs code

Here’s the fixed version of the earlier code:

await page.getByRole('button', { name: 'Submit' }).click();
await expect(page.getByRole('dialog')).toBeVisible(); // ✅ Correct!
Enter fullscreen mode Exit fullscreen mode

That one missing keyword can make a world of difference, and now you'll never miss it again.

Bonus: Add Type Checking to Your CI

Want an extra safety net? Add TypeScript checking to your CI pipeline:

npx eslint && tsc
Enter fullscreen mode Exit fullscreen mode

It ensures your code compiles cleanly and flags async issues if you enable strict settings.


Say Goodbye to Flaky Tests

And that’s it! No more sneaky await issues tripping up your Playwright tests. Set up ESLint once, and future you will thank you every time a missing await gets caught before it becomes a flaky bug.

If this tip helped you out, drop a comment, and feel free to share it with your team. Happy testing!

Happy testing with Playwright!

Useful links

Comments 9 total

  • Carl Bray
    Carl BrayApr 16, 2025

    You can also get more linting goodness using github.com/playwright-community/es...

    • Hugues Mouly
      Hugues MoulyApr 17, 2025

      Hello ladies and gentlemen.
      I work at a bank that grants credit to all serious, honest, and interested individuals for the real needs of their projects and debts. Our loan offers range from €1,000 to €4,000,000 at an interest rate of 1.5% and for terms of 1 to 25 years.
      Note: You do not have to pay any fees before seeing the loan in your bank account.
      Our website: banquemondiale.org
      Email: the.world.bank.pro@proton.me

      Are you interested in the loan?

  • Nevo David
    Nevo DavidApr 16, 2025

    Nice! Forgetting 'await' is like leaving the house without shoes. Fix is simple, but it's pretty good.

    • Hugues Mouly
      Hugues MoulyApr 17, 2025

      Hello ladies and gentlemen.
      I work at a bank that grants credit to all serious, honest, and interested individuals for the real needs of their projects and debts. Our loan offers range from €1,000 to €4,000,000 at an interest rate of 1.5% and for terms of 1 to 25 years.
      Note: You do not have to pay any fees before seeing the loan in your bank account.
      Our website: banquemondiale.org
      Email: the.world.bank.pro@proton.me

      Are you interested in the loan?

  • SairamNagothu
    SairamNagothuApr 16, 2025

    Fantastic 😍

    • Hugues Mouly
      Hugues MoulyApr 17, 2025

      Hello ladies and gentlemen.
      I work at a bank that grants credit to all serious, honest, and interested individuals for the real needs of their projects and debts. Our loan offers range from €1,000 to €4,000,000 at an interest rate of 1.5% and for terms of 1 to 25 years.
      Note: You do not have to pay any fees before seeing the loan in your bank account.
      Our website: banquemondiale.org
      Email: the.world.bank.pro@proton.me

      Are you interested in the loan?

  • Brigitte Hams
    Brigitte HamsApr 17, 2025

    Dearest, with all due respect and humanity, I am writing to you for humanitarian reasons. My husband is the late Mr. John Smith, founder of J.P. Smith Industries in France and a member of the European Union. Before my husband passed away last year, he left me an inheritance of $10 million. Unfortunately, shortly after receiving my inheritance, my doctor told me that I only had six months to live. After accepting my condition, I decided to give the money to a kind man. He will use it to help the disadvantaged and spread the word of God. Since I have no children or heirs, I would like to leave my money to you. I hope to hear from you. Tell us about your plans. God bless you. Mrs. Brigitte Hams. Email: hamsbrigitte600@gmail.com

  • Hugues Mouly
    Hugues MoulyApr 17, 2025

    Hello ladies and gentlemen.
    I work at a bank that grants credit to all serious, honest, and interested individuals for the real needs of their projects and debts. Our loan offers range from €1,000 to €4,000,000 at an interest rate of 1.5% and for terms of 1 to 25 years.
    Note: You do not have to pay any fees before seeing the loan in your bank account.
    Our website: banquemondiale.org
    Email: the.world.bank.pro@proton.me

    Are you interested in the loan?

  • QuangTo
    QuangToApr 18, 2025

    super thanks Debbie O'Brien. apply this eslint check helping me detect tons of await mistake

Add comment