Jest Snapshot tests failing #967
Replies: 3 comments 2 replies
-
Hey! Thank you for your question! Internally we mock the I wonder if you can mock functions from within a package somehow 🤔 One thing we can look into (can't promise an ETA) is creating a "test" build where this is mocked already. OR we can detect If you can get it working with Jest mocking features that would be awesome, you can look at the implementation from the link above! |
Beta Was this translation helpful? Give feedback.
-
Was there ever a resolution here? I'm running into the same problem |
Beta Was this translation helpful? Give feedback.
-
There might be a solve in newer versions of headless ui where React.useId is used instead of their default implementation. In that case, you should be able to mock React.useId to return a stable value. I can't find a solve for the older version of headless ui though... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We want to use Headlessui with Jest Snapshot tests. Unfortunately the tests often fail, because the order of the executed tests changes (for example when executing only one test) and therefore the auto generated ids by the
useId
hook are different.As we think this has to be solvable we ask for help. Maybe we miss something? is there a way to mock the hook during tests (we can't get it to work 😅 )? Or is there another trick?
Beta Was this translation helpful? Give feedback.
All reactions