When writing tests for a fixable rule with RuleTester
, you can assert the autofix output
of your test cases.
As of ESLint 7, test cases that trigger an autofix are required to provide the output
property.
However, it can be easy to forget to assert the output of a particular test case, leading to the autofix being untested. And even tests that do not trigger an autofix can benefit from asserting that they have no autofix using output: null
.
This rule ensures all invalid test cases have output
assertions.
Examples of incorrect code for this rule:
/* eslint eslint-plugin/require-test-output: error */
new RuleTester().run('example-rule', rule, {
valid: [],
invalid: [
{
code: 'foo',
output: 'bar',
errors: ['baz'],
},
{
code: 'bar',
errors: ['baz'],
},
],
});
Examples of correct code for this rule:
/* eslint eslint-plugin/require-test-output: error */
new RuleTester().run('example-rule', rule, {
valid: [],
invalid: [
{
code: 'foo',
output: 'bar',
errors: ['baz'],
},
{
code: 'bar',
output: 'qux',
errors: ['baz'],
},
{
code: 'foo',
output: null, // asserts that there is no autofix
errors: ['baz'],
},
],
});
This rule takes an optional object containing:
boolean
--consistent
-- only requireoutput
assertions when some test cases have them (defaultfalse
)