-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathuse-t.js
63 lines (58 loc) · 1.53 KB
/
use-t.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
'use strict';
const test = require('ava');
const avaRuleTester = require('eslint-ava-rule-tester');
const rule = require('../rules/use-t');
const ruleTester = avaRuleTester(test, {
env: {
es6: true,
},
parserOptions: {
sourceType: 'module',
},
});
const parameterNotNamedTErrors = [{
message: 'Test parameter should be named `t`.',
}];
const header = 'const test = require(\'ava\');\n';
ruleTester.run('use-t', rule, {
valid: [
header + 'test();',
header + 'test(() => {});',
header + 'test(t => {});',
header + 'test("test name", t => {});',
header + 'test((t, foo) => {});',
header + 'test(function (t) {});',
header + 'test(testFunction);',
header + 'test.macro(testFunction);',
header + 'test.macro(t => {});',
header + 'test.macro({exec: t => {}, title: () => "title"});',
header + 'test.todo("test name");',
// Shouldn't be triggered since it's not a test file
'test(foo => {});',
header + 'test(macro, arg1, (p1) => {})',
header + 'test("name", macro, arg1, (p1) => {})',
header + 'test("name", macro, (p1) => {})',
],
invalid: [
{
code: header + 'test(foo => {});',
errors: parameterNotNamedTErrors,
},
{
code: header + 'test("test name", foo => {});',
errors: parameterNotNamedTErrors,
},
{
code: header + 'test(function (foo) {});',
errors: parameterNotNamedTErrors,
},
{
code: header + 'test.macro(function (foo) {});',
errors: parameterNotNamedTErrors,
},
{
code: header + 'test.macro({ exec(foo) {} });',
errors: parameterNotNamedTErrors,
},
],
});