Skip to content

Commit 5ddce16

Browse files
committed
test: add new cases
1 parent 32d7ed3 commit 5ddce16

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/__tests__/__fixtures__/createBannedAttributeTestCases.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ export default ({ preferred, negatedPreferred, attribute }) => {
3939
],
4040
output: `const el = screen.getByText("foo"); expect(el).${negatedPreferred}`,
4141
},
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+
},
4251
]
4352
: [];
4453
const directChecks = /-/.test(attribute)
@@ -63,13 +72,22 @@ export default ({ preferred, negatedPreferred, attribute }) => {
6372
output: `expect(getByText('foo')).${[negatedPreferred]}`,
6473
},
6574
{
66-
code: `expect(getByText('foo').${attribute}).toBe(true)`,
75+
code: `const el = getByText('foo'); expect(el.${attribute}).toBe(true)`,
6776
errors: [
6877
{
6978
message: `Use ${preferred} instead of checking .${attribute} directly`,
7079
},
7180
],
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]}`,
7391
},
7492
];
7593

@@ -203,6 +221,14 @@ export default ({ preferred, negatedPreferred, attribute }) => {
203221
},
204222
],
205223
},
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+
},
206232
],
207233
};
208234
};

0 commit comments

Comments
 (0)