/
prefer-to-have-length.test.ts
45 lines (42 loc) · 1.36 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
import { TSESLint } from '@typescript-eslint/experimental-utils';
import rule from '../prefer-to-have-length';
const ruleTester = new TSESLint.RuleTester({
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);',
'expect(files["length"]).toBe(1);',
],
invalid: [
// todo: support this
// {
// code: 'expect(files["length"]).toBe(1);',
// errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }],
// output: 'expect(files).toHaveLength(1);',
// },
{
code: 'expect(files.length).toBe(1);',
errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }],
output: 'expect(files).toHaveLength(1);',
},
{
code: 'expect(files.length).toEqual(1);',
errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }],
output: 'expect(files).toHaveLength(1);',
},
{
code: 'expect(files.length).toStrictEqual(1);',
errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }],
output: 'expect(files).toHaveLength(1);',
},
],
});