Skip to content

prefer-web-first-assertions rule reports "Replace toString() with undefined()" for unsupported methods #383

@josephzaksheskePDL

Description

@josephzaksheskePDL

When using the prefer-web-first-assertions rule, I encountered a confusing lint error:

error  Replace toString() with undefined()  playwright/prefer-web-first-assertions

This happens when calling expect(await locator.toString()).toBe(...) or similar, where the method (toString) is not in the rule’s supported methods list.

Expected Behavior
The rule should ignore or skip unsupported methods (like toString) and not report an error or suggest an invalid fix.

Actual Behavior
The rule tries to access properties on an undefined methodConfig, resulting in a message like "Replace toString() with undefined()". This is confusing and not actionable.

Steps to Reproduce

  1. Write a test with:
await expect(await locator.toString()).toBe('something')
  1. Run ESLint with this rule enabled.
  2. Observe the error message.

Suggested Fix
Add a guard so that if methodConfig is undefined, the rule does not report or attempt to fix the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions