Skip to content

Commit fe93ad7

Browse files
bdoughertysindresorhus
authored andcommitted
Update prefer-power-assert to accept only true (#118)
1 parent f6919aa commit fe93ad7

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

docs/rules/prefer-power-assert.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/related/eslint-plugin-ava/docs/rules/prefer-power-assert.md)
44

5-
- [`t.truthy()`](https://github.com/sindresorhus/ava#truthyvalue-message) __(You can do [most things](https://github.com/sindresorhus/ava#enhanced-assertion-messages) with this one)__
6-
- [`t.deepEqual()`](https://github.com/sindresorhus/ava#deepequalvalue-expected-message)
7-
- [`t.notDeepEqual()`](https://github.com/sindresorhus/ava#notdeepequalvalue-expected-message)
8-
- [`t.throws()`](https://github.com/sindresorhus/ava#throwsfunctionpromise-error-message)
9-
- [`t.notThrows()`](https://github.com/sindresorhus/ava#notthrowsfunctionpromise-message)
10-
- [`t.pass()`](https://github.com/sindresorhus/ava#passmessage)
11-
- [`t.fail()`](https://github.com/sindresorhus/ava#failmessage)
5+
- [`t.true()`](https://github.com/avajs/ava#truevalue-message)
6+
- [`t.deepEqual()`](https://github.com/avajs/ava#deepequalvalue-expected-message)
7+
- [`t.notDeepEqual()`](https://github.com/avajs/ava#notdeepequalvalue-expected-message)
8+
- [`t.throws()`](https://github.com/avajs/ava#throwsfunctionpromise-error-message)
9+
- [`t.notThrows()`](https://github.com/avajs/ava#notthrowsfunctionpromise-message)
10+
- [`t.pass()`](https://github.com/avajs/ava#passmessage)
11+
- [`t.fail()`](https://github.com/avajs/ava#failmessage)
1212

1313
Useful for people wanting to fully embrace the power of [power-assert](https://github.com/power-assert-js/power-assert).
1414

@@ -19,7 +19,13 @@ Useful for people wanting to fully embrace the power of [power-assert](https://g
1919
import test from 'ava';
2020

2121
test(t => {
22+
t.truthy(foo);
23+
t.falsy(foo);
24+
t.false(foo === bar);
2225
t.is(foo, bar);
26+
t.not(foo, bar);
27+
t.regex(foo, bar);
28+
t.ifError(error);
2329
});
2430
```
2531

@@ -30,6 +36,10 @@ test(t => {
3036
import test from 'ava';
3137

3238
test(t => {
33-
t.truthy(foo === bar);
39+
t.true(foo === bar);
40+
t.deepEqual(foo, bar);
41+
t.notDeepEqual(foo, bar);
42+
t.throws(foo);
43+
t.notThrows(bar);
3444
});
3545
```

rules/prefer-power-assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const deepStrictEqual = require('deep-strict-equal');
44
const createAvaRule = require('../create-ava-rule');
55

66
const notAllowed = [
7+
'truthy',
78
'falsy',
8-
'true',
99
'false',
1010
'is',
1111
'not',

test/prefer-power-assert.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ function testNotAllowedMethod(methodName) {
3434
}
3535

3636
const notAllowedMethods = [
37+
'truthy(foo)',
3738
'falsy(foo)',
38-
'true(foo)',
3939
'false(foo)',
4040
'is(foo, bar)',
4141
'not(foo, bar)',
@@ -65,11 +65,13 @@ function testAllowedMethod(methodName) {
6565
}
6666

6767
const allowedMethods = [
68-
'truthy(foo)',
68+
'true(foo)',
6969
'deepEqual(foo, bar)',
7070
'notDeepEqual(foo, bar)',
7171
'throws(block)',
72-
'notThrows(block)'
72+
'notThrows(block)',
73+
'pass(foo)',
74+
'fail(foo)'
7375
];
7476

7577
for (const methodName of allowedMethods) {
@@ -81,12 +83,12 @@ function testWithModifier(modifier) {
8183
ruleTester.run('prefer-power-assert', rule, {
8284
valid: [
8385
{
84-
code: `import test from 'ava';\n test.${modifier}(t => { t.truthy(foo); });`
86+
code: `import test from 'ava';\n test.${modifier}(t => { t.true(foo); });`
8587
}
8688
],
8789
invalid: [
8890
{
89-
code: `import test from 'ava';\n test.${modifier}(t => { t.falsy(foo); });`,
91+
code: `import test from 'ava';\n test.${modifier}(t => { t.is(foo); });`,
9092
errors
9193
}
9294
]
@@ -103,12 +105,12 @@ function testDeclaration(declaration) {
103105
ruleTester.run('prefer-power-assert', rule, {
104106
valid: [
105107
{
106-
code: `${declaration}\n test(t => { t.truthy(foo); });`
108+
code: `${declaration}\n test(t => { t.true(foo); });`
107109
}
108110
],
109111
invalid: [
110112
{
111-
code: `${declaration}\n test(t => { t.falsy(foo); });`,
113+
code: `${declaration}\n test(t => { t.is(foo); });`,
112114
errors
113115
}
114116
]
@@ -153,7 +155,7 @@ test('misc', () => {
153155
ruleTester.run('prefer-power-assert', rule, {
154156
valid: [
155157
{
156-
code: `import test from 'ava';\n test.cb(function (t) { t.truthy(foo); t.end(); });`
158+
code: `import test from 'ava';\n test.cb(function (t) { t.true(foo); t.end(); });`
157159
},
158160
// shouldn't be triggered since it's not a test file
159161
{

0 commit comments

Comments
 (0)