@@ -72,6 +72,24 @@ ruleTester.run("prefer-to-have-attribute", rule, {
72
72
] ,
73
73
output : `expect(getByText("yes")).toHaveAttribute("data-blah", expect.stringMatching(/foo/))` ,
74
74
} ,
75
+ {
76
+ code : `expect(getByText("yes").getAttribute("data-blah")).toBe("")` ,
77
+ errors : [
78
+ {
79
+ message : "Use toHaveAttribute instead of asserting on getAttribute" ,
80
+ } ,
81
+ ] ,
82
+ output : `expect(getByText("yes")).toHaveAttribute("data-blah", "")` ,
83
+ } ,
84
+ {
85
+ code : `expect(getByText("yes").getAttribute("data-blah")).toBe('')` ,
86
+ errors : [
87
+ {
88
+ message : "Use toHaveAttribute instead of asserting on getAttribute" ,
89
+ } ,
90
+ ] ,
91
+ output : `expect(getByText("yes")).toHaveAttribute("data-blah", '')` ,
92
+ } ,
75
93
{
76
94
code : `expect(getByText('foo').hasAttribute('foo')).toBe(null)` ,
77
95
errors : [
@@ -171,6 +189,24 @@ ruleTester.run("prefer-to-have-attribute", rule, {
171
189
] ,
172
190
output : 'expect(element).toHaveAttribute("foo", "bar")' ,
173
191
} ,
192
+ {
193
+ code : `expect(getByText("yes").getAttribute("data-blah")).toEqual("")` ,
194
+ errors : [
195
+ {
196
+ message : "Use toHaveAttribute instead of asserting on getAttribute" ,
197
+ } ,
198
+ ] ,
199
+ output : `expect(getByText("yes")).toHaveAttribute("data-blah", "")` ,
200
+ } ,
201
+ {
202
+ code : `expect(getByText("yes").getAttribute("data-blah")).toEqual('')` ,
203
+ errors : [
204
+ {
205
+ message : "Use toHaveAttribute instead of asserting on getAttribute" ,
206
+ } ,
207
+ ] ,
208
+ output : `expect(getByText("yes")).toHaveAttribute("data-blah", '')` ,
209
+ } ,
174
210
{
175
211
code : 'expect(element.getAttribute("foo")).toStrictEqual("bar")' ,
176
212
errors : [
@@ -180,6 +216,24 @@ ruleTester.run("prefer-to-have-attribute", rule, {
180
216
] ,
181
217
output : 'expect(element).toHaveAttribute("foo", "bar")' ,
182
218
} ,
219
+ {
220
+ code : `expect(getByText("yes").getAttribute("data-blah")).toStrictEqual("")` ,
221
+ errors : [
222
+ {
223
+ message : "Use toHaveAttribute instead of asserting on getAttribute" ,
224
+ } ,
225
+ ] ,
226
+ output : `expect(getByText("yes")).toHaveAttribute("data-blah", "")` ,
227
+ } ,
228
+ {
229
+ code : `expect(getByText("yes").getAttribute("data-blah")).toStrictEqual('')` ,
230
+ errors : [
231
+ {
232
+ message : "Use toHaveAttribute instead of asserting on getAttribute" ,
233
+ } ,
234
+ ] ,
235
+ output : `expect(getByText("yes")).toHaveAttribute("data-blah", '')` ,
236
+ } ,
183
237
{
184
238
code : 'expect(element.getAttribute("foo")).toBe(null)' ,
185
239
errors : [
0 commit comments