Repository navigation
feat: warn about unmounted elements with eventDiagnostics - #1970
Open
mdjastrzebski wants to merge 1 commit into
Open
mdjastrzebski wants to merge 1 commit into
mdjastrzebski wants to merge 1 commit into
Conversation
`fireEvent` skipped events on unmounted elements silently, and `userEvent` either warned about missing responder handlers or not at all. With `eventDiagnostics` on, both now say the element is unmounted and suggest querying it again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1970 +/- ##
=======================================
Coverage 98.57% 98.57%
=======================================
Files 87 87
Lines 1750 1760 +10
Branches 460 483 +23
=======================================
+ Hits 1725 1735 +10
Misses 24 24
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a test keeps a reference to an element and a re-render removes it,
fireEventanduserEventskip events on that element on purpose. WitheventDiagnosticson, they didn't report this clearly:fireEventskipped the event without any warning.userEvent.press()warned about missingresponderGrantandresponderReleasehandlers, which points in the wrong direction.userEvent.type()didn't warn, because it still updated the detachedTextInput's native state.With
eventDiagnosticson, both now warn that the element is unmounted and suggest querying it again:Interactionrecords whether its target was mounted when the interaction started. A handler that unmounts the element duringpress()therefore still doesn't warn.Test plan
fireEventwarns about an unmounted element wheneventDiagnosticsis on (inline snapshot).userEvent.press()anduserEvent.type()warn about an unmounted element (inline snapshots).yarn test(961 passed),yarn typecheck,yarn lint,yarn format:check,yarn docs:check.Known gap: after the whole tree is unmounted,
fireEventanduserEventstill throw test-renderer's "Cannot access .container on unmounted test renderer" error. This PR doesn't change that.🤖 Generated with Claude Code