Skip to content

Mock useId so it can be reset before each tests#33214

Draft
dbkr wants to merge 16 commits intodevelopfrom
dbkr/how_on_earth_does_nobody_else_have_this_problem_with_useid
Draft

Mock useId so it can be reset before each tests#33214
dbkr wants to merge 16 commits intodevelopfrom
dbkr/how_on_earth_does_nobody_else_have_this_problem_with_useid

Conversation

@dbkr
Copy link
Copy Markdown
Member

@dbkr dbkr commented Apr 20, 2026

Which will hopefully make IDs consistent regardless of whether tests are run individually or as a suite.

Adding this commit separately before updating ALL THE IDS.

Checklist

Which will hopefully make IDs consistent regardless of whether tests
are run individually or as a suite.

Adding this commit separately before updating ALL THE IDS.
@dbkr dbkr requested a review from a team as a code owner April 20, 2026 16:06
@dbkr dbkr added the T-Task Tasks for the team like planning label Apr 20, 2026
@dbkr dbkr requested review from florianduros and t3chguy April 20, 2026 16:06
@dbkr dbkr marked this pull request as draft April 20, 2026 16:10
Comment thread apps/web/test/setupTests.ts Outdated

jest.spyOn(React, "useId").mockImplementation(() => {
// IDs need to be consistent for re-renders of the same component otherwise Radix etc get confused.
// We can use a ref to store the one we generated 9which is broadly similar to how react's version
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo

& see if it works
dbkr added 3 commits April 21, 2026 13:40
otherwise it removes the ock the global beforeEach just added

Also, this should be restoreMocks rather than resetMocks: the former
actually puts the original functions back, the latter just removes
the mock impl which just makes the mock return undefined which is
not super helpful.
So we always restore all mocks before every test run but before the
useId mock is added back.
…does_nobody_else_have_this_problem_with_useid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-Task Tasks for the team like planning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants