Mock useId so it can be reset before each tests#33214
Draft
Conversation
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.
t3chguy
reviewed
Apr 20, 2026
|
|
||
| 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 |
& see if it works
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
…does_nobody_else_have_this_problem_with_useid
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.
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
public/exportedsymbols have accurate TSDoc documentation.