Skip to content

Commit 9be11cf

Browse files
committed
Recognize t.try() assertion
Fixes #272
1 parent bb971ca commit 9be11cf

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

Diff for: rules/assertion-arguments.js

+8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ const create = context => {
115115
return;
116116
}
117117

118+
if (members[0] === 'try') {
119+
if (gottenArgs < 1) {
120+
report(node, 'Not enough arguments. Expected at least 1.');
121+
}
122+
123+
return;
124+
}
125+
118126
const nArgs = expectedNbArguments[members[0]];
119127

120128
if (!nArgs) {

Diff for: test/assertion-arguments.js

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ ruleTester.run('assertion-arguments', rule, {
105105
testCase('always', 't.is.skip(\'same\', \'same\', \'message\');'),
106106
testCase('always', 't.snapshot(value, \'message\');'),
107107
testCase('always', 't.timeout(100);'),
108+
testCase('always', 't.try(tt => tt.pass());'),
109+
testCase('always', 't.try(tt => tt.pass(), 1, 2);'),
110+
testCase('always', 't.try(\'title\', tt => tt.pass(), 1, 2);'),
108111

109112
// Shouldn't be triggered since it's not a test file
110113
testCase('always', 't.true(true);', [], false),
@@ -134,6 +137,10 @@ ruleTester.run('assertion-arguments', rule, {
134137
testCase('never', 't.is.skip(\'same\', \'same\');'),
135138
testCase('never', 't.snapshot(value);'),
136139
testCase('never', 't.timeout(100);'),
140+
testCase('never', 't.try(tt => tt.pass());'),
141+
testCase('never', 't.try(tt => tt.pass(), 1, 2);'),
142+
testCase('never', 't.try(\'title\', tt => tt.pass(), 1, 2);'),
143+
137144
// Shouldn't be triggered since it's not a test file
138145
testCase('never', 't.true(true, \'message\');', [], false),
139146

@@ -181,6 +188,7 @@ ruleTester.run('assertion-arguments', rule, {
181188
testCase(false, 't.is.skip(\'same\');', tooFewError(2)),
182189
testCase(false, 't.snapshot();', tooFewError(1)),
183190
testCase(false, 't.timeout();', tooFewError(1)),
191+
testCase(false, 't.try();', tooFewError(1)),
184192

185193
// Too many arguments
186194
testCase(false, 't.plan(1, \'extra argument\');', tooManyError(1)),

Diff for: test/use-t-well.js

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ ruleTester.run('use-t-well', rule, {
6565
testCase('t.context.foo(a, a);'),
6666
testCase('foo.t.bar(a, a);'),
6767
testCase('t.timeout(100);'),
68+
testCase('t.try(tt => tt.pass())'),
69+
testCase('t.try(tt => tt.pass(), 1, 2)'),
70+
testCase('t.try(\'title\', tt => tt.pass())'),
71+
testCase('t.try(\'title\', tt => tt.pass(), 1, 2)'),
6872
// Shouldn't be triggered since it's not a test file
6973
testCase('t.foo(a, a);', false),
7074
testCase('t.foo;', false)

Diff for: util.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ const assertionMethodsNumArguments = new Map([
116116
['throws', 1],
117117
['throwsAsync', 1],
118118
['true', 1],
119-
['truthy', 1]
119+
['truthy', 1],
120+
['try', 1]
120121
]);
121122

122123
const assertionMethodNames = [...assertionMethodsNumArguments.keys()];

0 commit comments

Comments
 (0)