Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request : mock navigate entirely with jest #475

Open
SimonChaumet opened this issue Jun 18, 2021 · 0 comments
Open

Feature request : mock navigate entirely with jest #475

SimonChaumet opened this issue Jun 18, 2021 · 0 comments

Comments

@SimonChaumet
Copy link

SimonChaumet commented Jun 18, 2021

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

  • Provide all necessary variables in export
  • Create a common function for navigate
  • Maybe provide a hash history (I know that hash history is for react-router@v6 but if I develop one, should I make a PR ?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant