Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/rules/prefer-power-assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/re
- [`t.assert()`](https://github.com/avajs/ava/blob/master/docs/03-assertions.md#assertvalue-message)
- [`t.deepEqual()`](https://github.com/avajs/ava/blob/master/docs/03-assertions.md#deepequalvalue-expected-message)
- [`t.notDeepEqual()`](https://github.com/avajs/ava/blob/master/docs/03-assertions.md#notdeepequalvalue-expected-message)
- [`t.like()`](https://github.com/avajs/ava/blob/master/docs/03-assertions.md#likevalue-selector-message)
- [`t.throws()`](https://github.com/avajs/ava/blob/master/docs/03-assertions.md#throwsfn-expected-message)
- [`t.notThrows()`](https://github.com/avajs/ava/blob/master/docs/03-assertions.md#notthrowsfn-message)
- [`t.pass()`](https://github.com/avajs/ava/blob/master/docs/03-assertions.md#passmessage)
Expand Down
4 changes: 4 additions & 0 deletions rules/assertion-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const expectedNbArguments = {
min: 2,
max: 3
},
like: {
min: 2,
max: 3
},
not: {
min: 2,
max: 3
Expand Down
9 changes: 8 additions & 1 deletion test/assertion-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ruleTester.run('assertion-arguments', rule, {
testCase(false, 't.ifError(new Error(), \'message\');'),
testCase(false, 't.is.skip(\'same\', \'same\', \'message\');'),
testCase(false, 't.is(\'same\', \'same\', \'message\');'),
testCase(false, 't.like({}, {}, \'message\');'),
testCase(false, 't.not(\'not\', \'same\', \'message\');'),
testCase(false, 't.notDeepEqual({}, {a: true}, \'message\');'),
testCase(false, 't.notThrows(Promise.resolve(), \'message\');'),
Expand All @@ -67,6 +68,7 @@ ruleTester.run('assertion-arguments', rule, {
testCase(false, 't.ifError(new Error());'),
testCase(false, 't.is.skip(\'same\', \'same\');'),
testCase(false, 't.is(\'same\', \'same\');'),
testCase(false, 't.like({}, {});'),
testCase(false, 't.not(\'not\', \'same\');'),
testCase(false, 't.notDeepEqual({}, {a: true});'),
testCase(false, 't.notThrows(Promise.resolve());'),
Expand Down Expand Up @@ -97,6 +99,7 @@ ruleTester.run('assertion-arguments', rule, {
testCase('always', 't.not(\'not\', \'same\', \'message\');'),
testCase('always', 't.deepEqual({}, {}, \'message\');'),
testCase('always', 't.notDeepEqual({}, {a: true}, \'message\');'),
testCase('always', 't.like({}, {}, \'message\');'),
testCase('always', 't.throws(Promise.reject(), Error, \'message\');'),
testCase('always', 't.notThrows(Promise.resolve(), \'message\');'),
testCase('always', 't.regex(a, /a/, \'message\');'),
Expand Down Expand Up @@ -129,6 +132,7 @@ ruleTester.run('assertion-arguments', rule, {
testCase('never', 't.not(\'not\', \'same\');'),
testCase('never', 't.deepEqual({}, {});'),
testCase('never', 't.notDeepEqual({}, {a: true});'),
testCase('never', 't.like({}, {});'),
testCase('never', 't.throws(Promise.reject());'),
testCase('never', 't.throws(Promise.reject(), Error);'),
testCase('never', 't.notThrows(Promise.resolve());'),
Expand Down Expand Up @@ -182,6 +186,7 @@ ruleTester.run('assertion-arguments', rule, {
testCase(false, 't.not(\'not\');', tooFewError(2)),
testCase(false, 't.deepEqual({});', tooFewError(2)),
testCase(false, 't.notDeepEqual({});', tooFewError(2)),
testCase(false, 't.like({});', tooFewError(2)),
testCase(false, 't.throws();', tooFewError(1)),
testCase(false, 't.notThrows();', tooFewError(1)),
testCase(false, 't.regex(a);', tooFewError(2)),
Expand All @@ -206,6 +211,7 @@ ruleTester.run('assertion-arguments', rule, {
testCase(false, 't.not(\'not\', \'same\', \'message\', \'extra argument\');', tooManyError(3)),
testCase(false, 't.deepEqual({}, {}, \'message\', \'extra argument\');', tooManyError(3)),
testCase(false, 't.notDeepEqual({}, {a: true}, \'message\', \'extra argument\');', tooManyError(3)),
testCase(false, 't.like({}, {}, \'message\', \'extra argument\');', tooManyError(3)),
testCase(false, 't.throws(Promise.reject(), Error, \'message\', \'extra argument\');', tooManyError(3)),
testCase(false, 't.notThrows(Promise.resolve(), \'message\', \'extra argument\');', tooManyError(2)),
testCase(false, 't.regex(a, /a/, \'message\', \'extra argument\');', tooManyError(3)),
Expand All @@ -227,6 +233,7 @@ ruleTester.run('assertion-arguments', rule, {
testCase('always', 't.not(\'not\', \'same\');', missingError),
testCase('always', 't.deepEqual({}, {});', missingError),
testCase('always', 't.notDeepEqual({}, {a: true});', missingError),
testCase('always', 't.like({}, {});', missingError),
testCase('always', 't.throws(Promise.reject());', missingError),
testCase('always', 't.throws(Promise.reject(), Error);', missingError),
testCase('always', 't.notThrows(Promise.resolve());', missingError),
Expand All @@ -236,7 +243,6 @@ ruleTester.run('assertion-arguments', rule, {
testCase('always', 't.skip.is(\'same\', \'same\');', missingError),
testCase('always', 't.is.skip(\'same\', \'same\');', missingError),
testCase('always', 't.snapshot(value);', missingError),

testCase('never', 't.pass(\'message\');', foundError),
testCase('never', 't.fail(\'message\');', foundError),
testCase('never', 't.truthy(\'unicorn\', \'message\');', foundError),
Expand All @@ -247,6 +253,7 @@ ruleTester.run('assertion-arguments', rule, {
testCase('never', 't.not(\'not\', \'same\', \'message\');', foundError),
testCase('never', 't.deepEqual({}, {}, \'message\');', foundError),
testCase('never', 't.notDeepEqual({}, {a: true}, \'message\');', foundError),
testCase('never', 't.like({}, {}, \'message\');', foundError),
testCase('never', 't.throws(Promise.reject(), Error, \'message\');', foundError),
testCase('never', 't.notThrows(Promise.resolve(), \'message\');', foundError),
testCase('never', 't.regex(a, /a/, \'message\');', foundError),
Expand Down
1 change: 1 addition & 0 deletions test/prefer-power-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const allowedMethods = [
'assert(foo)',
'deepEqual(foo, bar)',
'notDeepEqual(foo, bar)',
'like(foo, bar)',
'throws(block)',
'notThrows(block)',
'pass(foo)',
Expand Down
9 changes: 9 additions & 0 deletions test/use-t-well.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ ruleTester.run('use-t-well', rule, {
testCase('t.try(tt => tt.pass(), 1, 2)'),
testCase('t.try(\'title\', tt => tt.pass())'),
testCase('t.try(\'title\', tt => tt.pass(), 1, 2)'),
testCase('t.like'),
testCase('t.like(v, v)'),
testCase('t.like(actual, {}, "")'),
testCase('t.like.skip(v, v)'),
// Shouldn't be triggered since it's not a test file
testCase('t.foo(a, a);', false),
testCase('t.foo;', false)
Expand Down Expand Up @@ -205,6 +209,11 @@ ruleTester.run('use-t-well', rule, {
{
code: testCase('t.deepEqual.context(a, a);'),
errors: [error('Unknown assertion method `.context`.')]
},
{
code: testCase('t.lik(a, a);'),
output: testCase('t.like(a, a);'),
errors: [error('Misspelled `.like` as `.lik`.')]
}
]
});
1 change: 1 addition & 0 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const assertionMethodsNumberArguments = new Map([
['falsy', 1],
['ifError', 1],
['is', 2],
['like', 2],
['not', 2],
['notDeepEqual', 2],
['notRegex', 2],
Expand Down