reach / router

https://reach.tech/router
MIT License
6.9k stars 326 forks source link

Feature request : mock navigate entirely with jest #475

Open SimonChaumet opened 3 years ago

SimonChaumet commented 3 years ago

I tried to mock the navigate function since jsom doesn't handle html5 navigations but it seems that the navigate function exported in the root component is not the same as the one exported from history.

Is there a common function between those two that I can mock ?

See #76 for the main navigate mock See #371 for the history navigate mock EDIT: there is also the redirect which is missing

But while these 2 seems to work, you need to mock them differently and know in advance which one will be called (so you can't change a link into a button for example).

What I tried

As I said earlier I tried to mock the main navigate function but it's not triggered with a Link.

I tried to mock the Link but the BaseContext is not exported, nor is the shouldNavigate.

I tried to change the History to a HashHistory but the result isn't what I wanted since it doesn't test HTML5 navigations and I need to create my own history and mock it.

Solutions