Open History to see the last commit
1// Re-export test utilities from ai-client
2import { renderHook } from '@testing-library/preact'
3import { useChat } from '../src/use-chat'
4import type { RenderHookResult } from '@testing-library/preact'
5import type { UseChatOptions, UseChatReturn } from '../src/types'
6
7export function createInterruptResumeSnapshot() {
8 const pendingInterrupts = [
9 {
10 id: 'staged-interrupt',
11 reason: 'confirmation',
12 metadata: {
13 'tanstack:interruptBinding': {
14 kind: 'generic' as const,
15 interruptId: 'staged-interrupt',
16 interruptedRunId: 'run-1',
17 generation: 1,
18 responseSchemaHash: 'none',
19 },
20 },
21 },
22 {
23 id: 'invalid-interrupt',
24 reason: 'confirmation',
25 metadata: {
26 'tanstack:interruptBinding': {
27 kind: 'generic' as const,
28 interruptId: 'invalid-interrupt',
29 interruptedRunId: 'run-1',
30 generation: 1,
31 responseSchemaHash: 'none',
32 },
33 },
34 },
35 ]
36 return {
37 resumeState: { threadId: 'thread-1', runId: 'run-1' },
38 pendingInterrupts,
39 }
40}
41
42export {
43 createMockConnectionAdapter,
44 createTextChunks,
45 createToolCallChunks,
46} from '../../ai-client/tests/test-utils'
47
48/**
49 * Render the useChat hook with testing utilities
50 *
51 * @example
52 * ```typescript
53 * const { result } = renderUseChat({
54 * connection: createMockConnectionAdapter({ chunks: [...] })
55 * });
56 *
57 * await result.current.sendMessage("Hello");
58 * ```
59 */
60export function renderUseChat(
61 options: UseChatOptions = {} as UseChatOptions,
62): RenderHookResult<UseChatReturn, UseChatOptions> {
63 return renderHook(() => useChat(options))
64}