Skip to content

feat: add no-test-id-queries rule #1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

StyleShit
Copy link

Closes #279

@Belco90 Belco90 self-requested a review May 12, 2025 06:01
Copy link

codecov bot commented May 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.29%. Comparing base (26d360e) to head (50c44c6).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1006      +/-   ##
==========================================
+ Coverage   96.27%   96.29%   +0.01%     
==========================================
  Files          46       47       +1     
  Lines        2472     2481       +9     
  Branches     1025     1026       +1     
==========================================
+ Hits         2380     2389       +9     
  Misses         92       92              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


## Further Reading

- [about `getByTestId`](https://testing-library.com/docs/queries/bytestid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (blocking): Please add a link to the "Not querying by text" section from "Common mistakes with React Testing Library" post.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, done

export type MessageIds = 'noTestIdQueries';
type Options = [];

const QUERIES_REGEX = /^(get|query|getAll|queryAll|find|findAll)ByTestId$/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (blocking): Please build this regex using the ALL_QUERIES_VARIANTS from the utils file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done

];

ruleTester.run(RULE_NAME, rule, {
valid: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (blocking): Please add another valid test that includes calls to methods containing *TestId at the end but not matching the regex reported by the rule (e.g. caculateTestId, getTestId, searchByTestId)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@StyleShit StyleShit requested a review from Belco90 May 12, 2025 08:11
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.

New rule suggestion: no-test-id-queries
2 participants