Skip to content

Commit

Permalink
Recognize t.try() assertion
Browse files Browse the repository at this point in the history
Fixes #272
  • Loading branch information
novemberborn committed Feb 16, 2020
1 parent bb971ca commit f350675
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions rules/assertion-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ const create = context => {
return;
}

if (members[0] === 'try') {
if (gottenArgs < 1) {
report(node, 'Not enough arguments. Expected at least 1.');
}

return;
}

const nArgs = expectedNbArguments[members[0]];

if (!nArgs) {
Expand Down
8 changes: 8 additions & 0 deletions test/assertion-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ ruleTester.run('assertion-arguments', rule, {
testCase('always', 't.is.skip(\'same\', \'same\', \'message\');'),
testCase('always', 't.snapshot(value, \'message\');'),
testCase('always', 't.timeout(100);'),
testCase('always', 't.try(tt => tt.pass());'),
testCase('always', 't.try(tt => tt.pass(), 1, 2);'),
testCase('always', 't.try(\'title\', tt => tt.pass(), 1, 2);'),

// Shouldn't be triggered since it's not a test file
testCase('always', 't.true(true);', [], false),
Expand Down Expand Up @@ -134,6 +137,10 @@ ruleTester.run('assertion-arguments', rule, {
testCase('never', 't.is.skip(\'same\', \'same\');'),
testCase('never', 't.snapshot(value);'),
testCase('never', 't.timeout(100);'),
testCase('never', 't.try(tt => tt.pass());'),
testCase('never', 't.try(tt => tt.pass(), 1, 2);'),
testCase('never', 't.try(\'title\', tt => tt.pass(), 1, 2);'),

// Shouldn't be triggered since it's not a test file
testCase('never', 't.true(true, \'message\');', [], false),

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

// Too many arguments
testCase(false, 't.plan(1, \'extra argument\');', tooManyError(1)),
Expand Down
4 changes: 4 additions & 0 deletions test/use-t-well.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ ruleTester.run('use-t-well', rule, {
testCase('t.context.foo(a, a);'),
testCase('foo.t.bar(a, a);'),
testCase('t.timeout(100);'),
testCase('t.try(tt => tt.pass())'),
testCase('t.try(tt => tt.pass(), 1, 2)'),
testCase('t.try(\'title\', tt => tt.pass())'),
testCase('t.try(\'title\', tt => tt.pass(), 1, 2)'),
// Shouldn't be triggered since it's not a test file
testCase('t.foo(a, a);', false),
testCase('t.foo;', false)
Expand Down
3 changes: 2 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const assertionMethodsNumArguments = new Map([
['throws', 1],
['throwsAsync', 1],
['true', 1],
['truthy', 1]
['truthy', 1],
['try', 1]
]);

const assertionMethodNames = [...assertionMethodsNumArguments.keys()];
Expand Down

0 comments on commit f350675

Please sign in to comment.