We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
history
Router
In v5 it was possible to pass in history for testing purposes.
Either allow this again or make another suggestion for how to best test isolated components that navigate away. E. g.:
const HomeButten = () => { const navigate = useNavigate() return <button onClick={navigate('/')}>Home</button> }
import { createMemoryHistory } from "history"; import { render } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; test('HomeButton when clicked navigates to root', () => { history = createMemoryHistory({ initialEntries: ['/foo'] }); render(<Router history={mockHistory}><HomeButton /></Router>); userEvent.click(screen.getByText("Home")); expect(history.location.pathname).toBe("/"); })
The text was updated successfully, but these errors were encountered:
See #7586, which will implement this.
This is also essentially a duplicate of #8264, but I'll keep it open since it comes at the problem from the other direction (read vs write)
Sorry, something went wrong.
For the time being, see this stack overflow answer to get tests working again in v6: https://stackoverflow.com/a/69859510
This is now possible with HistoryRouter in 6.1.0.
No branches or pull requests
What is the new or updated feature that you are suggesting?
In v5 it was possible to pass in
history
for testing purposes.Why should this feature be included?
Either allow this again or make another suggestion for how to best test isolated components that navigate away. E. g.:
The text was updated successfully, but these errors were encountered: