Skip to content

Commit 2d86d15

Browse files
committed
feedback
1 parent 41fafa4 commit 2d86d15

File tree

3 files changed

+103
-15
lines changed

3 files changed

+103
-15
lines changed

docs/rules/no-typeerror-with-notthrows.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Prevent specifying error type in `t.notThrows()`
1+
# No specifying error type in `t.notThrows()`
22

3-
AVA will fail if error type is specified with `t.notThrows()`.
3+
AVA will fail if error constructor is specified in the second argument of `t.notThrows()`.
44

55

66
## Fail

rules/no-typeerror-with-notthrows.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ const create = context => {
2727

2828
const functionArgName = node.arguments[1].name;
2929

30-
if (calleeProperty === 'notThrows') {
30+
if (calleeProperty === 'notThrows' || calleeProperty === 'notThrowsAsync') {
3131
if (errorNameRegex.test(functionArgName)) {
3232
context.report({
3333
node,
34-
message: 'Do not specify Error in t.notThrows()'
34+
message: 'Do not specify an error constructor in the second argument of t.notThrows()'
3535
});
3636
}
3737
}
@@ -44,6 +44,7 @@ module.exports = {
4444
meta: {
4545
docs: {
4646
url: util.getDocsUrl(__filename)
47-
}
47+
},
48+
type: 'problem'
4849
}
4950
};

test/no-typeerror-with-notthrows.js

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,114 @@ const ruleTester = avaRuleTester(test, {
88
}
99
});
1010

11-
const errors = [{ruleId: 'no-typerror-with-notthrows'}];
11+
const errors = [{ruleId: 'no-typeerror-with-notthrows'}];
1212

1313
const header = `const test = require('ava');\n`; // eslint-disable-line quotes
1414

1515
ruleTester.run('no-typeerror-with-notthrows', rule, {
1616
valid: [
17-
`${header} test('some test',t => {t.notThrows(() => {t.pass();});});`,
18-
`${header} test(t => {t.notThrows(() => {t.pass();});});`,
19-
`${header} test(t => {t.throws(() => {t.pass();}, TypeError);});`,
20-
`${header} test(t => {t.end(); })`,
21-
`${header} test('some test',t => {t.notThrows(() => {t.pass();}, true);});`,
22-
`${header} test('some test',t => {t.notThrows(() => {t.pass();}, 'some string');});`,
23-
`${header} test('some test',t => {t.notThrows(() => {t.pass();}, {firstName:'some', lastName: 'object'});});`
17+
`${header}
18+
test('some test',t => {
19+
t.notThrows(() => {
20+
t.pass();
21+
});
22+
});`,
23+
24+
`${header}
25+
test(t => {
26+
t.notThrows(() => {
27+
t.pass();
28+
});
29+
});`,
30+
31+
`${header}
32+
test(t => {
33+
t.throws(() => {
34+
t.pass();
35+
}, TypeError);
36+
});`,
37+
38+
`${header}
39+
test(t => {
40+
t.end(); })`,
41+
42+
`${header}
43+
test('some test',t => {
44+
t.notThrows(() => {
45+
t.pass();
46+
}, true);
47+
});`,
48+
49+
`${header}
50+
test('some test',t => {
51+
t.notThrows(() => {
52+
t.pass();
53+
}, 'some string');
54+
});`,
55+
56+
`${header}
57+
test('some test',t => {
58+
t.notThrows(() => {
59+
t.pass();
60+
}, {firstName:'some', lastName: 'object'});
61+
});`,
62+
63+
`${header}
64+
test('some test',t => {
65+
t.notThrowsAsync(() => {
66+
t.pass();
67+
});
68+
});`,
69+
70+
`${header}
71+
test(t => {
72+
t.notThrowsAsync(() => {
73+
t.pass();
74+
});
75+
});`,
76+
77+
`${header}
78+
test('some test',t => {
79+
t.notThrowsAsync(() => {
80+
t.pass();
81+
}, {firstName:'some', lastName: 'object'});
82+
});`
2483
],
2584
invalid: [
2685
{
27-
code: `${header} test(t => {t.notThrows(() => {t.pass();}, TypeError);});`,
86+
code: `${header}
87+
test(t => {
88+
t.notThrows(() => {
89+
t.pass();
90+
}, TypeError);
91+
});`,
92+
errors
93+
},
94+
{
95+
code: `${header}
96+
test('some test',t => {
97+
t.notThrows(() => {
98+
t.pass();
99+
}, TypeError);
100+
});`,
101+
errors
102+
},
103+
{
104+
code: `${header}
105+
test(t => {
106+
t.notThrowsAsync(() => {
107+
t.pass();
108+
}, TypeError);
109+
});`,
28110
errors
29111
},
30112
{
31-
code: `${header} test('some test',t => {t.notThrows(() => {t.pass();}, TypeError);});`,
113+
code: `${header}
114+
test('some test',t => {
115+
t.notThrowsAsync(() => {
116+
t.pass();
117+
}, TypeError);
118+
});`,
32119
errors
33120
}
34121
]

0 commit comments

Comments
 (0)