Open History to see the last commit
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})