Skip to content

Change Request: Add options to rule-tester requiring certain assertions #19921

@ST-DDT

Description

@ST-DDT

ESLint version

v9.30.1

What problem do you want to solve?

I try to improve the quality of some (invalid) rule tests, by making sure they all test the same properties.
Specifically I want to ensure, I (and future developers) test for

  • individual errors instead of error counts
  • and test for specific error messages and locations instead of partial checks

What do you think is the correct solution?

I have considered two similar solutions:

  1. Add assertionOptions/options: { requireMessage: boolean; requireLocation: boolean } to RuleTester constructor
  2. Add assertionOptions/options: { requireMessage: boolean; requireLocation: boolean; requiredBlocks: Array<'valid', 'invalid'> } to RuleTester's run method

The second option would make it possible to run multiple test runs with the same runner instance but different options.

Participation

  • I am willing to submit a pull request for this change.

Additional comments

Requiring the location would require the full location (might be configurable with boolean | 'full')

Continuation of #19904

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusioncoreRelates to ESLint's core APIs and featuresenhancementThis change enhances an existing feature of ESLint

Type

No type

Projects

Status

Implementing

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions