TanStackT
TanStackโ€ข2y agoโ€ข
6 replies
developed-pink

router mock for tests and stories

What's the best way to have a mock implementation of the router? For example:
- we have components that we want to render in storybook, but they depend on useParams(). Ideally, we'd just wrap it in a Provider with a given path.
- we have cypress component tests, where we mount a component and then interact with it. It might e.g. click a link, but it shouldn't really navigate to that route (because the test is scoped to a component). Ideally, we'd set the navigate method of the router to a spy.

In nextJs, we had next-router-mock, a 3rd party package that would mock the router via a Provider. It worked okay (but not great). Is there anything for the TanStack Router? Thanks ๐Ÿ™
Was this page helpful?