playwright-community / eslint-plugin-playwright

ESLint plugin for Playwright
https://www.npmjs.com/package/eslint-plugin-playwright
MIT License
281 stars 39 forks source link

no-standalone-expect rule triggered when calling assertions in expect.extend blocks for custom matchers #319

Closed nickhall closed 1 month ago

nickhall commented 1 month ago

When writing custom matchers using the code provided by the docs, the calls to baseExtend are flagged by the no-standalone-expect rule.

import { expect as baseExpect } from '@playwright/test';

const expect = baseExpect.extend({
  async someMatcher() {
    // triggers the error
    await baseExpect(true).toBeTruthy();
  }
}

I would expect that this scenario wouldn't trigger the rule.

carlbray commented 1 month ago

You might need to declare aliases https://github.com/playwright-community/eslint-plugin-playwright/blob/main/README.md#aliased-playwright-globals

{
  "settings": {
    "playwright": {
      "globalAliases": {
        "test": ["myTest"],
        "expect": ["myExpect"]
      }
    }
  }
}
nickhall commented 1 month ago

Thank you, I think that should handle this use case.