Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { renderToStringAsync } from 'solid-js/web'
3import {
4 RouterProvider,
5 createMemoryHistory,
6 createRootRoute,
7 createRoute,
8 createRouter,
9} from '../../src'
10import { ClientOnly } from '../../src/ClientOnly'
11import type { RouterHistory } from '../../src'
12β
13function createTestRouter(initialHistory?: RouterHistory) {
14 const history =
15 initialHistory ?? createMemoryHistory({ initialEntries: ['/'] })
16β
17 const rootRoute = createRootRoute({})
18β
19 const indexRoute = createRoute({
20 getParentRoute: () => rootRoute,
21 path: '/',
22 component: () => (
23 <div>
24 <p>Index Route</p>
25 <ClientOnly fallback={<div data-testid="loading">Loading...</div>}>
26 <div data-testid="client-only-content">Client Only Content</div>
27 </ClientOnly>
28 </div>
29 ),
30 })
31β
32 const routeTree = rootRoute.addChildren([indexRoute])
33 const router = createRouter({ routeTree, history })
34β
35 return {
36 router,
37 routes: { indexRoute },
38 }
39}
40β
41describe('ClientOnly (server)', () => {
42 it('should render fallback during SSR', async () => {
43 const { router } = createTestRouter()
44 await router.load()
45β
46 // Initial render (SSR)
47 const html = await renderToStringAsync(() => (
48 <RouterProvider router={router} />
49 ))
50β
51 expect(html).include('Loading...')
52 expect(html).not.include('Client Only Content')
53 })
54})