In the parent component the link is being rendered
import { Link } from '@tanstack/react-router';
export default function Parent() {
return (
<div><Link to='/'>Test</Link></div>
)
}
in the test case i’m mocking the link
vi.mock('@tanstack/react-router', () => {
return {
default: () => <a href="/">Test</a>
}
});
But i’m getting the following error
Uncaught TypeError: Cannot read properties of null (reading 'buildLocation')
Tried below case as well, only the not found route is loaded and not the link.
test('Should render tanstack router link', () => {
const rootRoute = createRootRoute();
const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
component: () => <Link to="/">Hello</Link>,
});
const router = createRouter({
routeTree: rootRoute.addChildren([indexRoute]),
basepath: '/',
});
render(<RouterProvider router={router} />);
});
My questions are
- How to mock tanstack router links
- How to test a link mocking the tanstack router setup, I have simplified here with a link actually the component is bigger with lot of links.