-
Notifications
You must be signed in to change notification settings - Fork 41
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
MemoryRouterProvider url property does not work properly #108
Comments
I've encountered the same issue before as well. next-router-mock/src/MemoryRouterProvider/MemoryRouterProvider.tsx Lines 26 to 29 in 3abed1b
To resolve this issue, you can create a wrapper for MemoryRouterProvider. Set the url passed in via props using setCurrentUrl as shown below and pass the remaining props other than url to MemoryRouterProvider: import singletonRouter from 'next-router-mock';
import { MemoryRouterProvider } from 'next-router-mock/MemoryRouterProvider';
import type { MemoryRouterProviderProps } from 'next-router-mock/dist/MemoryRouterProvider/MemoryRouterProvider';
const SingletonRouterProvider = ({ url, ...rest }: MemoryRouterProviderProps) => {
useEffect(() => {
if (!url) {
return;
}
singletonRouter.setCurrentUrl(url);
}, [url]);
return <MemoryRouterProvider {...rest} />;
};
const renderWithRouter = (ui: React.ReactElement, { route = "/" } = {}) => {
const wrapper = ({ children }: { children: React.ReactNode }) => (
<SingletonRouterProvider url={route}>{children}</SingletonRouterProvider>
);
return {
user: userEvent.setup(),
...render(ui, { wrapper }),
};
}; |
It appears that this implementation was added in the following PR, but could you please explain the reason behind it? |
@scottrippey Are you here? |
I'm trying to text links with this package and I am getting inconsistent behavior.
I defined a custom render as follows:
And I'm using it on my test like this:
Logging the router path we get:
Yeah, it should be "Current Path /streaming".
Also, after clicking on the button, it should navigate easily, but it seems the route is always overwritten to be the given one and it does not change.
When using it without
url
property it works well, and navigates correctly.It seems I got the property wrong, it should work as an initial route, right? Could you write an example of writing it as a provider with options using testing library?
The text was updated successfully, but these errors were encountered: