@@ -39,6 +39,15 @@ export default ({ preferred, negatedPreferred, attribute }) => {
39
39
] ,
40
40
output : `const el = screen.getByText("foo"); expect(el).${ negatedPreferred } ` ,
41
41
} ,
42
+ {
43
+ code : `const el = screen.getByRole("button"); expect(el).not.${ preferred } ` ,
44
+ errors : [
45
+ {
46
+ message : `Use ${ negatedPreferred } instead of not.${ preferred } ` ,
47
+ } ,
48
+ ] ,
49
+ output : `const el = screen.getByRole("button"); expect(el).${ negatedPreferred } ` ,
50
+ } ,
42
51
]
43
52
: [ ] ;
44
53
const directChecks = / - / . test ( attribute )
@@ -63,13 +72,22 @@ export default ({ preferred, negatedPreferred, attribute }) => {
63
72
output : `expect(getByText('foo')).${ [ negatedPreferred ] } ` ,
64
73
} ,
65
74
{
66
- code : `expect( getByText('foo').${ attribute } ).toBe(true)` ,
75
+ code : `const el = getByText('foo'); expect(el .${ attribute } ).toBe(true)` ,
67
76
errors : [
68
77
{
69
78
message : `Use ${ preferred } instead of checking .${ attribute } directly` ,
70
79
} ,
71
80
] ,
72
- output : `expect(getByText('foo')).${ [ preferred ] } ` ,
81
+ output : `const el = getByText('foo'); expect(el).${ [ preferred ] } ` ,
82
+ } ,
83
+ {
84
+ code : `const el = getByRole('button'); expect(el.${ attribute } ).toBe(true)` ,
85
+ errors : [
86
+ {
87
+ message : `Use ${ preferred } instead of checking .${ attribute } directly` ,
88
+ } ,
89
+ ] ,
90
+ output : `const el = getByRole('button'); expect(el).${ [ preferred ] } ` ,
73
91
} ,
74
92
] ;
75
93
@@ -203,6 +221,14 @@ export default ({ preferred, negatedPreferred, attribute }) => {
203
221
} ,
204
222
] ,
205
223
} ,
224
+ {
225
+ code : `const el = getByRole("button", { name: 'My Button' }); expect(el).toHaveProperty('${ attribute } ', foo)` ,
226
+ errors : [
227
+ {
228
+ message : `Use ${ preferred } instead of toHaveProperty('${ attribute } ', foo)` ,
229
+ } ,
230
+ ] ,
231
+ } ,
206
232
] ,
207
233
} ;
208
234
} ;
0 commit comments