fireEvent.select does not wrap its automatic native focus in act
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, react
- Domain
- testing
Research direction
Start in src/fire-event.js at fireEvent.select, where the native node.focus() call sits outside the configured eventWrapper used by the surrounding select/keyup dispatches. Read how eventWrapper is configured (see the act wrapping introduced in #685) and wrap that same native focus call, without synthesizing focus events or reordering them. Done means the issue's repro passes — data-focused and data-blurred attributes flush before fireEvent.select returns and no outside-act warning — with the existing src/__tests__ suite green; add a regression test alongside the select tests.
Written by the indexing model from the issue text.
Description
This report was prepared with autonomous AI-agent assistance; it has not received human review.
On current main with React 18.3.1, fireEvent.select focuses an unfocused input or textarea, but React state updates in its onFocus and the previous element's onBlur are not flushed before the call returns. React also reports updates outside act.
import * as React from 'react'
import {render, screen, fireEvent} from '@testing-library/react'
function Example() {
const [focused, setFocused] = React.useState(false)
const [blurred, setBlurred] = React.useState(false)
return <>
<input aria-label="previous" onBlur={() => setBlurred(true)} />
<input aria-label="selection" onFocus={() => setFocused(true)}
data-focused={focused} data-blurred={blurred} />
</>
}
render(<Example />)
screen.getByRole('textbox', {name: 'previous'}).focus()
const input = screen.getByRole('textbox', {name: 'selection'})
fireEvent.select(input)
expect(document.activeElement).toBe(input) // passes
expect(input.getAttribute('data-focused')).toBe('true') // receives false
expect(input.getAttribute('data-blurred')).toBe('true')
The existing native node.focus() call in src/fire-event.js is outside the configured eventWrapper, unlike the surrounding select and keyup dispatches. Wrapping that same native focus call fixes the focus/blur updates without synthesizing focus events or changing their order.
Verified against rebuilt original and fixed public dist/pure exports on macOS, Node 18.20.8/24.21.0, React 18.3.1 and jsdom 20.0.3. Formal regressions fail twice on original production with two passing controls. The existing worker_threads MessageChannel test shim keeps raw Jest alive after tests in this environment; an evidence-only native Node setImmediate bridge permits natural exit. No forced exit or repository configuration change is part of the fix.
Related: #685 established automatic act wrapping; #1214 proposes a broader asynchronous fireEvent API, and #1429 changes event argument forwarding. Neither wraps select's native focus call.
- Dominant language
- JavaScript
- Stars
- 19.7k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from testing-library/react-testing-library
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
testing-library/react-testing-library#1466 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
testing-library/react-testing-library#1459 · 2 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
testing-library/react-testing-library#1430 · 1 comment ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)Possibly taken @swarnim02 claimed this 314 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
testing-library/react-testing-library#1421 · 1 comment ·
All issues in testing-library/react-testing-library
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 67/100
Morni-Team/pkmessenger#44 · 4 comments ·
Maintainers usually reply within 1 day
-
status/needs-triage type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
PKU-YuanGroup/OpenAI4S#218 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
debpalash/VoiceStudio#2678 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 3 days