# jest-dom/prefer-pressed 📝 Prefer toBePressed over checking attributes. 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). ## Rule Details 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: ```js 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: ```js expect(element).toBePressed(); expect(element).not.toBePressed(); expect(element).toHaveAttribute("aria-label"); expect(element).toBePartiallyPressed(); ``` ## When Not To Use It Don't use this rule if you: - don't use `jest-dom` - want to allow `.toHaveAttribute()` and `.toHaveProperty()` for `aria-pressed` ## Further Reading - [jest-dom `toBePressed`](https://github.com/testing-library/jest-dom#tobepressed)