📝 Prefer toBePressed over checking attributes.
🔧 This rule is automatically fixable by the --fix CLI option.
This rule aims to prevent false positives and improve readability and should
only be used with the @testing-library/jest-dom package. The rule is
autofixable and will replace any instances of .toHaveProperty() or
.toHaveAttribute() with .toBePressed(), .toBePartiallyPressed(), and
not.toBePressed() as appropriate.
Examples of incorrect code for this rule:
expect(element).toHaveProperty("aria-pressed", true);
expect(element).toHaveAttribute("aria-pressed", false);
expect(element).toHaveProperty("aria-pressed", something);
expect(element).toHaveAttribute("aria-pressed");
expect(element).not.toHaveProperty("aria-pressed");
expect(element).toHaveAttribute("aria-pressed", "mixed");
expect(element).not.not.toBePressed();Examples of correct code for this rule:
expect(element).toBePressed();
expect(element).not.toBePressed();
expect(element).toHaveAttribute("aria-label");
expect(element).toBePartiallyPressed();Don't use this rule if you:
- don't use
jest-dom - want to allow
.toHaveAttribute()and.toHaveProperty()foraria-pressed