Mocking useHistory breaks CompatRouter in tests #9871
Replies: 3 comments 1 reply
-
I am currently analyzing this same thing. I jumped straight into the v6 apis as we use microfrontends so on the remote I am working on there are just a few routes, but it is quite hard to make these tests work without mocking. We should not need to mock anything, it does not sound very healthy on a testing perspective. |
Beta Was this translation helpful? Give feedback.
-
Have you been able to find an optimal solution for this? We ran into the same issue and we just ended up wrapping |
Beta Was this translation helpful? Give feedback.
-
You should not mock You should create a For instance:
|
Beta Was this translation helpful? Give feedback.
-
I'm looking into migrating a very large codebase from v5 to v6. We'll be using the compat package. We have many tests that make assertions against
history
methods being called. They go something like this:I realize we will no longer access
history
directly and so all of our tests written around that will need to change. To complete the migration incrementally, I had assumed we would need to render<CompatRouter>
in tests and they would at least run while we migrate. But the code above will cause CompatRouter to throw - if I understand correctly,useHistory
is the glue between the internal v6 instance and the consumer's v5 instance within the compat package.Is there any formal guidance on how to deal with this kind of scenario?
I think a couple options are:
useHistory
to satisfy the needs of CompatRouter. But that would add more to the ceremony in every test that applies. Not a very appealing option.location
and focus our test assertions on that as a side effect of performing navigation?I'm sure there are lots of ways to arrange it, but I'd love to know if the remix team has specific thoughts for how to approach this specific case.
Beta Was this translation helpful? Give feedback.
All reactions