// @vitest-environment jsdom import "@testing-library/jest-dom/vitest"; import { render } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import Captcha from "./Captcha"; describe("Captcha CAP status contract", () => { it("reports solve, reset and client errors to the enclosing form", () => { const onStatusChange = vi.fn(); const { container } = render( ); const widget = container.querySelector("cap-widget"); expect(widget).not.toBeNull(); expect(onStatusChange).toHaveBeenLastCalledWith("pending"); widget!.dispatchEvent(new CustomEvent("solve")); expect(onStatusChange).toHaveBeenLastCalledWith("solved"); widget!.dispatchEvent(new CustomEvent("reset")); expect(onStatusChange).toHaveBeenLastCalledWith("pending"); widget!.dispatchEvent(new CustomEvent("error")); expect(onStatusChange).toHaveBeenLastCalledWith("error"); }); it("renders nothing when the public provider configuration is incomplete", () => { const { container } = render(); expect(container).toBeEmptyDOMElement(); }); });