-
Notifications
You must be signed in to change notification settings - Fork 61
/
no-mocha-arrows.js
103 lines (100 loc) · 4.03 KB
/
no-mocha-arrows.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { RuleTester } from 'eslint';
import plugin from '../../index.js';
const ruleTester = new RuleTester({
languageOptions: { ecmaVersion: 2017, sourceType: 'script' }
});
const expectedErrorMessage = 'Do not pass arrow functions to it()';
const errors = [{ message: expectedErrorMessage, column: 1, line: 1 }];
ruleTester.run('no-mocha-arrows', plugin.rules['no-mocha-arrows'], {
valid: [
'it()',
'it(function() { assert(something, false); })',
'it("should be false", function() { assert(something, false); })',
'it.only()',
'it(function(done) { assert(something, false); done(); })',
'it(function*() { assert(something, false) })',
'it(async function () { assert(something, false) })',
// In those examples, `it` is not a global.
'function it () {}; it(() => { console.log("okay") })',
'function it () {}; it.only(() => { console.log("okay") })',
'function it () {}; it(() => {}); it(() => {});',
'foo("", () => {}); const it = () => {}; it("", () => {});'
],
invalid: [
{
code: 'it(() => { assert(something, false); })',
errors,
output: 'it(function() { assert(something, false); })'
},
{
code: 'it(() => assert(something, false))',
errors,
output: 'it(function() { return assert(something, false); })'
},
{
code: 'it(done => assert(something, false))',
errors,
output: 'it(function(done) { return assert(something, false); })'
},
{
code: 'it("should be false", () => { assert(something, false); })',
errors,
output: 'it("should be false", function() { assert(something, false); })'
},
{
code: 'it.only(() => { assert(something, false); })',
errors: [{ message: 'Do not pass arrow functions to it.only()', column: 1, line: 1 }],
output: 'it.only(function() { assert(something, false); })'
},
{
code: 'it((done) => { assert(something, false); })',
errors,
output: 'it(function(done) { assert(something, false); })'
},
{
code: 'it(done => { assert(something, false); })',
errors,
output: 'it(function(done) { assert(something, false); })'
},
{
code: 'it("should be false", () => {\n assert(something, false);\n})',
errors,
output: 'it("should be false", function() {\n assert(something, false);\n})'
},
{
code: 'it(async () => { assert(something, false) })',
errors,
output: 'it(async function() { assert(something, false) })'
},
{
code: 'it(async () => assert(something, false))',
errors,
output: 'it(async function() { return assert(something, false); })'
},
{
code: 'it(async done => assert(something, false))',
errors,
output: 'it(async function(done) { return assert(something, false); })'
},
{
code: 'it(async (done) => assert(something, false))',
errors,
output: 'it(async function(done) { return assert(something, false); })'
},
{
code: 'it(async() => assert(something, false))',
errors,
output: 'it(async function() { return assert(something, false); })'
},
{
code: 'it(/*one*/async/*two*/(done)/*three*/=>/*four*/assert(something, false))',
errors,
output: 'it(/*one*/async function/*two*/(done)/*three*//*four*/ { return assert(something, false); })'
},
{
code: 'const foo = () => {}; foo("", () => {}); it(() => { assert(something, false); })',
errors: [{ message: expectedErrorMessage, column: 42, line: 1 }],
output: 'const foo = () => {}; foo("", () => {}); it(function() { assert(something, false); })'
}
]
});