Open History to see the last commit
1import { describe, expect, it, vi } from 'vitest'
2import { render, waitFor } from '@solidjs/testing-library'
3import {
4 createMemoryHistory,
5 createRootRoute,
6 createRoute,
7 createRouter,
8} from '../src'
9import { RouterProvider } from '../src/RouterProvider'
10β
11describe('Transitioner', () => {
12 it('should call router.load() when Transitioner mounts on the client', async () => {
13 const loader = vi.fn()
14 const rootRoute = createRootRoute()
15 const indexRoute = createRoute({
16 getParentRoute: () => rootRoute,
17 path: '/',
18 component: () => <div>Index</div>,
19 loader,
20 })
21β
22 const routeTree = rootRoute.addChildren([indexRoute])
23 const router = createRouter({
24 routeTree,
25 history: createMemoryHistory({
26 initialEntries: ['/'],
27 }),
28 })
29β
30 // Mock router.load() to verify it gets called
31 const loadSpy = vi.spyOn(router, 'load')
32β
33 render(() => <RouterProvider router={router} />)
34β
35 // Wait for the createRenderEffect to run and call router.load()
36 await waitFor(() => {
37 expect(loadSpy).toHaveBeenCalledTimes(1)
38 expect(loader).toHaveBeenCalledTimes(1)
39 })
40β
41 loadSpy.mockRestore()
42 })
43})