* Minimal dependency-free hook harness (the repo has no `@testing-library/react`). Mounts the hook in * a real React root under jsdom so effects and refs run exactly as in the app. Fake timers keep the * paced reveal from advancing, so each assertion observes the synchronous reveal decision only.
(initial: ProbeProps)
| 18 | * paced reveal from advancing, so each assertion observes the synchronous reveal decision only. |
| 19 | */ |
| 20 | function renderSmoothText(initial: ProbeProps) { |
| 21 | ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true |
| 22 | const container = document.createElement('div') |
| 23 | const root: Root = createRoot(container) |
| 24 | const props = { ...initial } |
| 25 | let latest = '' |
| 26 | |
| 27 | function Probe(p: ProbeProps) { |
| 28 | latest = useSmoothText(p.content, p.isStreaming, { snapOnNonAppend: p.snapOnNonAppend }) |
| 29 | return null |
| 30 | } |
| 31 | |
| 32 | const render = () => |
| 33 | act(() => { |
| 34 | root.render(<Probe {...props} />) |
| 35 | }) |
| 36 | render() |
| 37 | |
| 38 | return { |
| 39 | value: () => latest, |
| 40 | rerender: (next: Partial<ProbeProps>) => { |
| 41 | Object.assign(props, next) |
| 42 | render() |
| 43 | }, |
| 44 | unmount: () => act(() => root.unmount()), |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | const LONG = `# Existing Document\n\n${'Lorem ipsum dolor sit amet, '.repeat(8)}` |
| 49 |
no test coverage detected