Skip to content

fix(prefer-checked): don't flag aria-checked="mixed"#420

Merged
G-Rath merged 2 commits intotesting-library:mainfrom
shamrt-v:fix/prefer-checked-mixed-value
Feb 13, 2026
Merged

fix(prefer-checked): don't flag aria-checked="mixed"#420
G-Rath merged 2 commits intotesting-library:mainfrom
shamrt-v:fix/prefer-checked-mixed-value

Conversation

@shamrt-v
Copy link
Copy Markdown
Contributor

What:

  • Add excludeValues option to createBannedAttributeRule factory
  • Apply excludeValues: ["mixed"] to prefer-checked to stop incorrectly flagging aria-checked="mixed"

Why:

The prefer-checked rule incorrectly suggests not.toBeChecked() when it encounters toHaveAttribute('aria-checked', 'mixed'). The value "mixed" is a valid third state for aria-checked (representing an indeterminate/partially-checked state) and should not be treated as falsy. The correct matcher for this case is toBePartiallyChecked(), which is outside the scope of prefer-checked.

How:

  • Extended createBannedAttributeRule with an optional excludeValues parameter (defaults to [])
  • When a toHaveAttribute/toHaveProperty call has a second argument matching an excluded value, the rule skips it
  • The change is backwards-compatible — existing rules without excludeValues behave identically

Checklist:

  • Documentation — N/A (no user-facing doc changes needed)
  • Tests
  • Ready to be merged

Allow attribute rules to skip specific values (e.g. 'mixed') so
tri-state aria attributes are not incorrectly flagged. Apply to
prefer-checked to stop suggesting not.toBeChecked() for
aria-checked='mixed'.
Verify aria-checked='mixed' is not flagged by prefer-checked.
@shamrt-v shamrt-v changed the title fix: prevent prefer-checked from flagging aria-checked=\"mixed\" fix: prevent prefer-checked from flagging aria-checked="mixed" Feb 12, 2026
@shamrt-v shamrt-v marked this pull request as ready for review February 12, 2026 21:35
@G-Rath G-Rath changed the title fix: prevent prefer-checked from flagging aria-checked="mixed" fix(prefer-checked): don't flag aria-checked="mixed" Feb 13, 2026
@G-Rath G-Rath merged commit 60ab34a into testing-library:main Feb 13, 2026
85 checks passed
Aesthermortis added a commit to Aesthermortis/eslint-plugin-jest-dom that referenced this pull request May 4, 2026
Add generic attribute-value rule generation for replacing manual ARIA
mixed-state assertions with semantic jest-dom matchers.

- Add prefer-partially-checked for aria-checked="mixed"
- Add prefer-partially-pressed for aria-pressed="mixed"
- Reintroduce the all config for every exported rule
- Keep partial-state rules out of the recommended preset
- Add rule docs and split tests by matcher

Upstream-Context: testing-library#43
Upstream-Context: testing-library#419
Upstream-Context: testing-library#420
Related-Context: testing-library/jest-dom#249
Related-Context: testing-library/jest-dom#203
Related-Context: testing-library/jest-dom#692
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants