#Vitest renders App but not the Outlet content for "/"

15 messages · Page 1 of 1 (latest)

tall nebula
#

Can somebody point me in the right direction here?

Experimenting with TanStack Router and Unit Tests for UI.
Works partially but does not render Outlet for the "/" Route.

I have a test that does render(<RouterProvider router={testRouter} />); and successfully completes which uses a separate instance of a router which uses the generated routeTree.gen from the app. The content for the __root.tsx Route appears in the output of screen.debug() but it does not contain the content from the root index route i.e. the content of the <Outlet> which does show up fine when running the app normally. When doing await screen.findByText('<known-content>'); in that test it times out. The index route that does not render does use a loader (see below) but i assume that should be done in time (<100ms) or do i need to do something special to await that? Or is something else off in my approach?

export const Route = createFileRoute('/')({
  component: RouteComponent,
  loader: () => getResourceList(),
});
function RouteComponent() {
  const resourceTable = Route.useLoaderData();
  return <Menu resources={resourceTable} />;
}

I assume i am missing some basic understanding here.
Is this enough info to give me a hint here?

meager shadow
#

can you please provide a complete minimal example?

tall nebula
#

Ok. Will try to replicate in StackBlitz.

meager shadow
#

btw this thread might be interesting for you

#

#1318937332446920805 message

tall nebula
#

Would you say that the approach to use the full tree from the app is in general problematic and a bad idea and asking for trouble?

meager shadow
#

not necesarily

tall nebula
#

Ok. Thanks. Will investigate and try to build the repro.

tall nebula
meager shadow
#

you need to add a await testRouter.load()

tall nebula
#

Oh! Wow. Thanks for the quick feedback. Happy new year and all the best to you!

meager shadow
#

same to you!

#

btw you can also look at our unit tests on how to test things

tall nebula
#

I did look around in there but did not catch that one.