* Minimal dependency-free hook harness (the repo has no `@testing-library/react`). Mounts the hook * in a real React 19 root under jsdom so effects, refs, and timers run exactly as in the app.
(initial: ProbeProps)
| 27 | * in a real React 19 root under jsdom so effects, refs, and timers run exactly as in the app. |
| 28 | */ |
| 29 | function renderAutosave(initial: ProbeProps): { handle: HookHandle; props: ProbeProps } { |
| 30 | ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true |
| 31 | const container = document.createElement('div') |
| 32 | const root: Root = createRoot(container) |
| 33 | const props = { ...initial } |
| 34 | let latest = { saveStatus: 'idle' as SaveStatus, isDirty: false, saveImmediately: async () => {} } |
| 35 | |
| 36 | function Probe(p: ProbeProps) { |
| 37 | latest = useAutosave(p) |
| 38 | return null |
| 39 | } |
| 40 | |
| 41 | const render = () => { |
| 42 | act(() => { |
| 43 | root.render(<Probe {...props} />) |
| 44 | }) |
| 45 | } |
| 46 | render() |
| 47 | |
| 48 | const handle: HookHandle = { |
| 49 | status: () => latest.saveStatus, |
| 50 | isDirty: () => latest.isDirty, |
| 51 | saveImmediately: () => latest.saveImmediately(), |
| 52 | rerender: (next) => { |
| 53 | Object.assign(props, next) |
| 54 | render() |
| 55 | }, |
| 56 | unmount: () => act(() => root.unmount()), |
| 57 | } |
| 58 | return { handle, props } |
| 59 | } |
| 60 | |
| 61 | /** Flush pending microtasks (awaited promises) inside an act() boundary. */ |
| 62 | async function flush() { |
no test coverage detected