Change Request: Invalid test cases that yield suggestions should require a `suggestions` assertion
See original GitHub issueESLint version
8.0.0-rc.0
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
},
],
},
]
});
Participation
- I am willing to submit a pull request for this change.
Additional comments
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have opened an RFC for this issue, along with some related rule test validation improvements: https://github.com/eslint/rfcs/pull/84
Still planning to do this, assigned myself.