Skip to content

Write HTML. Render video. Built for agents.

461 B
Raw Blame
import { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach } from "vitest";

export function createHappyDomRootHarness() {
  const roots: Root[] = [];
  afterEach(() => {
    for (const root of roots.splice(0)) act(() => root.unmount());
    document.body.innerHTML = "";
  });
  return {
    mount(host: HTMLElement) {
      const root = createRoot(host);
      roots.push(root);
      return root;
    },
  };
}