/
prefer-to-be-truthy.test.ts
70 lines (68 loc) · 2.13 KB
/
prefer-to-be-truthy.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { describe, it } from 'vitest'
import ruleTester from '../utils/tester'
import rule, { RULE_NAME } from './prefer-to-be-truthy'
const messageId = 'preferToBeTruthy'
describe(RULE_NAME, () => {
it(RULE_NAME, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
'[].push(true)',
'expect("something");',
'expect(true).toBeTrue();',
'expect(false).toBeTrue();',
'expect(fal,se).toBeFalse();',
'expect(true).toBeFalse();',
'expect(value).toEqual();',
'expect(value).not.toBeTrue();',
'expect(value).not.toEqual();',
'expect(value).toBe(undefined);',
'expect(value).not.toBe(undefined);',
'expect(true).toBe(false)',
'expect(value).toBe();',
'expect(true).toMatchSnapshot();',
'expect("a string").toMatchSnapshot(true);',
'expect("a string").not.toMatchSnapshot();',
'expect(something).toEqual(\'a string\');',
'expect(true).toBe',
'expectTypeOf(true).toBe()'
],
invalid: [
{
code: 'expect(false).toBe(true);',
output: 'expect(false).toBeTruthy();',
errors: [{ messageId, column: 15, line: 1 }]
},
{
code: 'expectTypeOf(false).toBe(true);',
output: 'expectTypeOf(false).toBeTruthy();',
errors: [{ messageId, column: 21, line: 1 }]
},
{
code: 'expect(wasSuccessful).toEqual(true);',
output: 'expect(wasSuccessful).toBeTruthy();',
errors: [{ messageId, column: 23, line: 1 }]
},
{
code: 'expect(fs.existsSync(\'/path/to/file\')).toStrictEqual(true);',
output: 'expect(fs.existsSync(\'/path/to/file\')).toBeTruthy();',
errors: [{ messageId, column: 40, line: 1 }]
},
{
code: 'expect("a string").not.toBe(true);',
output: 'expect("a string").not.toBeTruthy();',
errors: [{ messageId, column: 24, line: 1 }]
},
{
code: 'expect("a string").not.toEqual(true);',
output: 'expect("a string").not.toBeTruthy();',
errors: [{ messageId, column: 24, line: 1 }]
},
{
code: 'expectTypeOf("a string").not.toStrictEqual(true);',
output: 'expectTypeOf("a string").not.toBeTruthy();',
errors: [{ messageId, column: 30, line: 1 }]
}
]
})
})
})