Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

hydrateStart.test.ts

33 lines968 Bytes

1import { afterEach, expect, test, vi } from 'vitest'
2import { hydrateStart } from '../hydrateStart'
3​
4const coreHydrateStart = vi.hoisted(() => vi.fn())
5​
6vi.mock('@tanstack/start-client-core/client', () => ({
7 hydrateStart: coreHydrateStart,
8}))
9​
10afterEach(() => {
11 delete window.$_TSR
12 coreHydrateStart.mockReset()
13})
14​
15test('signals streaming cleanup after hydration succeeds', async () => {
16 const router = {}
17 coreHydrateStart.mockResolvedValue(router)
18 const hydrated = vi.fn()
19 window.$_TSR = { h: hydrated } as any
20​
21 await expect(hydrateStart()).resolves.toBe(router)
22 expect(hydrated).toHaveBeenCalledTimes(1)
23})
24​
25test('signals streaming cleanup without hiding a hydration failure', async () => {
26 const error = new Error('hydration failed')
27 coreHydrateStart.mockRejectedValue(error)
28 const hydrated = vi.fn()
29 window.$_TSR = { h: hydrated } as any
30​
31 await expect(hydrateStart()).rejects.toBe(error)
32 expect(hydrated).toHaveBeenCalledTimes(1)
33})