Mounts a fresh hook instance and flushes the on-mount draft GET.
(opts: HookOptions)
| 190 | |
| 191 | /** Mounts a fresh hook instance and flushes the on-mount draft GET. */ |
| 192 | async function mountSession(opts: HookOptions): Promise<Session> { |
| 193 | const host = document.createElement('div'); |
| 194 | document.body.appendChild(host); |
| 195 | const resultRef: { current: HookResult | null } = { current: null }; |
| 196 | let root: Root; |
| 197 | await act(async () => { |
| 198 | root = createRoot(host); |
| 199 | root.render(<Harness opts={opts} resultRef={resultRef} />); |
| 200 | }); |
| 201 | await tick(0); // let the GET .then chain settle (sets hasMountedRef) |
| 202 | return { |
| 203 | result: resultRef, |
| 204 | rerender: async (next: HookOptions) => { |
| 205 | await act(async () => { |
| 206 | root.render(<Harness opts={next} resultRef={resultRef} />); |
| 207 | }); |
| 208 | }, |
| 209 | unmount: async () => { |
| 210 | await act(async () => { |
| 211 | root.unmount(); |
| 212 | }); |
| 213 | host.remove(); |
| 214 | }, |
| 215 | }; |
| 216 | } |
| 217 | |
| 218 | // --------------------------------------------------------------------------- |
| 219 | // Tests |
no test coverage detected