/
prefer-to-have-length.test.ts
70 lines (67 loc) · 2.27 KB
/
prefer-to-have-length.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 { TSESLint } from '@typescript-eslint/utils';
import rule from '../prefer-to-have-length';
import { espreeParser } from './test-utils';
const ruleTester = new TSESLint.RuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
},
});
ruleTester.run('prefer-to-have-length', rule, {
valid: [
'expect(files).toHaveLength(1);',
"expect(files.name).toBe('file');",
"expect(files[`name`]).toBe('file');",
'expect(result).toBe(true);',
`expect(user.getUserName(5)).resolves.toEqual('Paul')`,
`expect(user.getUserName(5)).rejects.toEqual('Paul')`,
'expect(a);',
],
invalid: [
{
code: 'expect(files["length"]).toBe(1);',
output: 'expect(files).toHaveLength(1);',
errors: [{ messageId: 'useToHaveLength', column: 25, line: 1 }],
},
{
code: 'expect(files["length"])["not"].toBe(1);',
output: 'expect(files)["not"].toHaveLength(1);',
errors: [{ messageId: 'useToHaveLength', column: 32, line: 1 }],
},
{
code: 'expect(files["length"])["toBe"](1);',
output: 'expect(files).toHaveLength(1);',
errors: [{ messageId: 'useToHaveLength', column: 25, line: 1 }],
},
{
code: 'expect(files["length"]).not["toBe"](1);',
output: 'expect(files).not.toHaveLength(1);',
errors: [{ messageId: 'useToHaveLength', column: 29, line: 1 }],
},
{
code: 'expect(files["length"])["not"]["toBe"](1);',
output: 'expect(files)["not"].toHaveLength(1);',
errors: [{ messageId: 'useToHaveLength', column: 32, line: 1 }],
},
{
code: 'expect(files.length).toBe(1);',
output: 'expect(files).toHaveLength(1);',
errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }],
},
{
code: 'expect(files.length).toEqual(1);',
output: 'expect(files).toHaveLength(1);',
errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }],
},
{
code: 'expect(files.length).toStrictEqual(1);',
output: 'expect(files).toHaveLength(1);',
errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }],
},
{
code: 'expect(files.length).not.toStrictEqual(1);',
output: 'expect(files).not.toHaveLength(1);',
errors: [{ messageId: 'useToHaveLength', column: 26, line: 1 }],
},
],
});