Component Library with hook using useLocation causing unit tests with MemoryRouter in main site to fail? #11867
Replies: 1 comment
-
Did a full clean of modules & deleted package-lock.json and this fixed the issue. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
We have a mono-repo with a common component library & two websites.
After updating
react-router-dom
from 6.16.0 to 6.26.0 unit tests in our two websites have started failing with the erroruseLocation() may be used only in the context of a "Router" component.
.We have a few hooks in the component library that use
useLocation
and these seem to be the issue with the test failures.The sites run fine after the update, its just the tests in the two sites that fail.
The sites use
BrowserRouter
, and the tests useMemoryRouter
.I created some simple components/hooks to diagnose this issue, and it definitely seems related to
MemoryRouter
and using hooks in the component library that useuseLocation
as when the hook is in the site the tests work.One fix/workaround would be move the common hooks in question to the sites, but i really don't want to do this.
I went back though the change log but couldn't see anything related to this, though i may have missed it.
Questions
Seems like now (based on error) the component library isn't been included under
MemoryRouter
any more?Any advice on ways forward?
Our Setup
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions