@@ -18,16 +18,34 @@ ruleTester.run('prefer-to-have-length', rule, {
18
18
`expect(user.getUserName(5)).resolves.toEqual('Paul')` ,
19
19
`expect(user.getUserName(5)).rejects.toEqual('Paul')` ,
20
20
'expect(a);' ,
21
- 'expect(files["length"]).toBe(1);' ,
22
21
] ,
23
22
24
23
invalid : [
25
- // todo: support this
26
- // {
27
- // code: 'expect(files["length"]).toBe(1);',
28
- // errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }],
29
- // output: 'expect(files).toHaveLength(1);',
30
- // },
24
+ {
25
+ code : 'expect(files["length"]).toBe(1);' ,
26
+ output : 'expect(files).toHaveLength(1);' ,
27
+ errors : [ { messageId : 'useToHaveLength' , column : 25 , line : 1 } ] ,
28
+ } ,
29
+ {
30
+ code : 'expect(files["length"])["not"].toBe(1);' ,
31
+ output : 'expect(files)["not"].toHaveLength(1);' ,
32
+ errors : [ { messageId : 'useToHaveLength' , column : 32 , line : 1 } ] ,
33
+ } ,
34
+ {
35
+ code : 'expect(files["length"])["toBe"](1);' ,
36
+ output : 'expect(files).toHaveLength(1);' ,
37
+ errors : [ { messageId : 'useToHaveLength' , column : 25 , line : 1 } ] ,
38
+ } ,
39
+ {
40
+ code : 'expect(files["length"]).not["toBe"](1);' ,
41
+ output : 'expect(files).not.toHaveLength(1);' ,
42
+ errors : [ { messageId : 'useToHaveLength' , column : 29 , line : 1 } ] ,
43
+ } ,
44
+ {
45
+ code : 'expect(files["length"])["not"]["toBe"](1);' ,
46
+ output : 'expect(files)["not"].toHaveLength(1);' ,
47
+ errors : [ { messageId : 'useToHaveLength' , column : 32 , line : 1 } ] ,
48
+ } ,
31
49
{
32
50
code : 'expect(files.length).toBe(1);' ,
33
51
output : 'expect(files).toHaveLength(1);' ,
@@ -43,5 +61,10 @@ ruleTester.run('prefer-to-have-length', rule, {
43
61
output : 'expect(files).toHaveLength(1);' ,
44
62
errors : [ { messageId : 'useToHaveLength' , column : 22 , line : 1 } ] ,
45
63
} ,
64
+ {
65
+ code : 'expect(files.length).not.toStrictEqual(1);' ,
66
+ output : 'expect(files).not.toHaveLength(1);' ,
67
+ errors : [ { messageId : 'useToHaveLength' , column : 26 , line : 1 } ] ,
68
+ } ,
46
69
] ,
47
70
} ) ;
0 commit comments