MCPcopy Create free account
hub / github.com/backnotprop/plannotator / mountSession

Function mountSession

packages/ui/codeAnnotationDraftPersistence.test.tsx:138–162  ·  view source on GitHub ↗
(opts: HookOptions)

Source from the content-addressed store, hash-verified

136const tick = (ms: number) => act(async () => new Promise((r) => setTimeout(r, ms)));
137
138async 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

Calls 3

renderMethod · 0.80
tickFunction · 0.70
removeMethod · 0.65

Tested by

no test coverage detected