Skip to content

fix(prefer-to-have-class): support direct elements - #499

Closed
YodHeVauHe wants to merge 1 commit into
testing-library:mainfrom
YodHeVauHe:cursor/fix-prefer-to-have-class-elements-ad17
Closed

YodHeVauHe wants to merge 1 commit into
testing-library:mainfrom
YodHeVauHe:cursor/fix-prefer-to-have-class-elements-ad17

Conversation

@YodHeVauHe

Copy link
Copy Markdown

Fixes #490.

prefer-to-have-class returned early unless the receiver was a Testing Library query, so expect(document.body).toHaveAttribute('class', …) was never reported. The guard now also allows a direct element.

npm test -- --runInBand passed: 12 suites, 621 tests. npm run lint passed.

Co-authored-by: ZaSourceCode <YodHeVauHe@users.noreply.github.com>
@G-Rath

G-Rath commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

While this looks to address what the OP described (and I think would be my preference at this point), that issue brought up

  1. we're inconsistent across our rules around this (and consistency is a goal)
  2. not having the check apparently caused a lot of false positives for some reasons in codebases

at this point I'd like more data before committing to a direction, as we've only heard from one user

@G-Rath G-Rath closed this Oct 4, 2026
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.

[prefer-to-have-class] does not trigger for elements, only for DTS queries

3 participants