File: consistent-output.md

package info (click to toggle)
node-eslint-plugin-eslint-plugin 2.3.0%2B~0.3.0-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 652 kB
  • sloc: javascript: 5,372; makefile: 34; sh: 1
file content (72 lines) | stat: -rw-r--r-- 1,718 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Enforce consistent use of output assertions in rule tests (consistent-output)

When writing tests for a fixable rule with `RuleTester`, you can assert the autofix output of your test cases. However, it can be easy to forget to assert the output of a particular test case.

## Rule Details

This rule aims to ensure that if any invalid test cases have output assertions, then all test cases have output assertions.

Examples of **incorrect** code for this rule:

```js
/* eslint eslint-plugin/consistent-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:

```js
/* eslint eslint-plugin/consistent-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,
      errors: ['baz']
    }
  ]
});

```

## Options

This rule takes an optional string enum option with one of the following values:

* `"consistent"` - (default) if any invalid test cases have output assertions, then all invalid test cases must have output assertions
* `"always"` - always require invalid test cases to have output assertions

## When Not To Use It

If you're not writing fixable rules, or you want to write test cases without output assertions, do not enable this rule.

## Further Reading

* [`RuleTester` documentation](http://eslint.org/docs/developer-guide/working-with-plugins#testing)