Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change Request: Invalid test cases that yield suggestions should require a `suggestions` assertion

See original GitHub issue

ESLint version


What problem do you want to solve?

  • Currently, it’s easy to forget to assert what suggestions a test case yields, or that a test case yields no assertions. As a result, this can be an area of poor test coverage, leading to bugs around suggestions.
  • It’s also inconvenient to have to add suggestions: [] to every single invalid test case for a rule or tests that do not produce suggestions, in order to achieve the desired test coverage.

What do you think is the correct solution?

Invalid test cases that yield suggestions should require a suggestions assertion.

This would be the same as how invalid test cases that produce an autofix require an output assertion, and fail with this error:

AssertionError [ERR_ASSERTION]: The rule fixed the code. Please add 'output' property.

This behavior was added as a breaking change in ESLint v7.

We should add a similar assertion for suggestions.

AssertionError [ERR_ASSERTION]: The rule violation produced a suggestion. Please add a 'suggestions' property to the error object.

Example of invalid test case with suggestions assertion:

new RuleTester().run('example-rule', rule, {
  valid: [],
  invalid: [
      code: `foo();`,
      output: null,
      errors: [
          messageId: 'bar',
          type: 'Property',
          suggestions: [], // or array of suggestions if rule provides them


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

Additional comments

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

bmishcommented, Dec 1, 2021

I have opened an RFC for this issue, along with some related rule test validation improvements:

bmishcommented, Nov 29, 2021

Still planning to do this, assigned myself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Negative Testing and How to Write Negative Test ...
In this article we will discuss what positive and negative testing are, how they're different and we'll describe some examples to understand ...
Read more >
REST API Testing Strategy: What Exactly Should You Test?
The test strategy is the high-level description of the test requirements from which a detailed test plan can later be derived, specifying individual...
Read more >
Advanced googletest Topics
As the function now returns void , you can use any assertion inside of it. If changing the function's type is not an...
Read more >
How to Write Better Unit Test Assertions - Diffblue
Checking for the right conditions in test assertions is important to produce valuable tests. So, what makes for good test assertions?
Read more >
CS 410/510 - Software Engineering class notes
Leads to defect testing: the test cases are designed to expose defects; the test cases can be deliberately obscure and need not reflect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found