(opts: HookOptions)
| 136 | const tick = (ms: number) => act(async () => new Promise((r) => setTimeout(r, ms))); |
| 137 | |
| 138 | async function mountSession(opts: HookOptions): Promise<Session> { |
| 139 | const host = document.createElement('div'); |
| 140 | document.body.appendChild(host); |
| 141 | const resultRef: { current: HookResult | null } = { current: null }; |
| 142 | let root: Root; |
| 143 | await act(async () => { |
| 144 | root = createRoot(host); |
| 145 | root.render(<Harness opts={opts} resultRef={resultRef} />); |
| 146 | }); |
| 147 | await tick(0); // let the on-mount GET .then chain settle (sets hasMountedRef) |
| 148 | return { |
| 149 | result: resultRef, |
| 150 | rerender: async (next: HookOptions) => { |
| 151 | await act(async () => { |
| 152 | root.render(<Harness opts={next} resultRef={resultRef} />); |
| 153 | }); |
| 154 | }, |
| 155 | unmount: async () => { |
| 156 | await act(async () => { |
| 157 | root.unmount(); |
| 158 | }); |
| 159 | host.remove(); |
| 160 | }, |
| 161 | }; |
| 162 | } |
| 163 | |
| 164 | // --------------------------------------------------------------------------- |
| 165 | // Tests |
no test coverage detected