Skip to content

fix: detect userEvent imported from custom module#1264

Merged
Belco90 merged 3 commits intotesting-library:mainfrom
snvfyy:pr/fix-user-event-custom-module
Mar 24, 2026
Merged

fix: detect userEvent imported from custom module#1264
Belco90 merged 3 commits intotesting-library:mainfrom
snvfyy:pr/fix-user-event-custom-module

Conversation

@snvfyy
Copy link
Contributor

@snvfyy snvfyy commented Mar 22, 2026

Checks

Changes

Adding a fallback to check the custom module import, similar to how findImportedTestingLibraryUtilSpecifier already does for other utils like fireEvent.

Affected rules: await-async-events, no-await-sync-events, no-unnecessary-act, no-wait-for-side-effects.

Context

Partially fixes #1253

When userEvent is imported from a custom module, rules relying on isUserEventUtil or isUserEventMethod don't detect it. This is because findImportedUserEventSpecifier only checks for @testing-library/user-event and not at custom modules.

We're fixing everything except prefer-user-event-setup. That one has a different root cause (it doesn't use the shared helpers), so the findImportedUserEventSpecifier fix doesn't help it.

@Belco90 Belco90 self-requested a review March 23, 2026 06:42
@Belco90 Belco90 added the bug Something isn't working label Mar 24, 2026
@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 91.42857% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.35%. Comparing base (9ce8966) to head (66b22c3).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...sting-library-rule/detect-testing-library-utils.ts 91.42% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1264   +/-   ##
=======================================
  Coverage   97.35%   97.35%           
=======================================
  Files          49       49           
  Lines        6012     6020    +8     
  Branches     1538     1544    +6     
=======================================
+ Hits         5853     5861    +8     
  Misses        157      157           
  Partials        2        2           

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

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

The bug fix looks fine to me, good job! Especially with the tests, those are great.

Codecov is complaining about the code coverage went down tho. What I'd do is adding new tests to tests/create-testing-library-rule.test.ts to cover the new user-event detection.

@snvfyy
Copy link
Contributor Author

snvfyy commented Mar 24, 2026

Thanks for the review! @Belco90

Tests added to create-testing-library-rule.test.ts too.

Copy link
Member

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

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

LGTM. The lines not covered are fine, so I'm skipping that.

@Belco90 Belco90 merged commit 8ef0782 into testing-library:main Mar 24, 2026
22 of 23 checks passed
@Belco90
Copy link
Member

Belco90 commented Mar 24, 2026

@all-contributors please add @snvfyy for code and test

@allcontributors
Copy link
Contributor

@Belco90

I've put up a pull request to add @snvfyy! 🎉

@github-actions
Copy link

🎉 This PR is included in version 7.16.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

userEvent not detected from custom module when testing-library/utils-module is configured

2 participants