test(frontend): useAuth's expiry test waits for the user, not the element (main is red) #785
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/useauth-test-race"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Main is red after #783 merged: run #10357,
useAuth.test.jsx, "Expected … Test User / Received: anonymous". Nothing in #783 touched auth, and the same tree had passed on #783's own PR run and inside #782's.Cause
AuthProviderrenders its children immediately, so the test's probe exists reading "anonymous" until/api/meanswers. The test did:findByTestIdresolves as soon as the element exists, and then the text is asserted, which on a loaded runner is a moment before the user arrives. The test has always been a race that usually won.Fix
It now waits for the name itself:
Five runs on a single CPU: 2/2 each.
The pattern
This is the third race of the same shape today. Each time, the test waits for the first thing on the page and asserts something that arrives later:
my_role(23c82b4).expect(await findBy…(…)).toHaveTextContent(…)appears in 50 places across the suite. Most are safe: where the element only appears once its data has arrived, existing is being ready. It races only when a placeholder with the same selector renders first and its content changes later. I haven't rewritten them blind. Worth a separate audit that classifies each site.🤖 Generated with Claude Code