import { cleanup, render, screen, } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import assert from "node:assert"; import { afterEach, describe, mock, test, } from "node:test"; import { Form } from "./index"; describe("Form", () => { afterEach(() => { cleanup(); }); test("renders rows with fields", () => { const rows = [ { cols: [ { field: { label: "Email", input: { type: "text", name: "email", }, }, }, ], }, ]; render(
); const input = document.querySelector("input[name='email']"); assert.notStrictEqual(input, null); assert.notStrictEqual(screen.queryByText("Email"), null); }); test("calls onSubmit when submit button is clicked", async () => { const user = userEvent.setup(); const onSubmit = mock.fn((event) => event.preventDefault()); render( ); await user.click(screen.getByRole("button", { name: "Submit" })); assert.strictEqual(onSubmit.mock.calls.length, 1); }); test("renders custom wrapper when isCustomWrapper=true", () => { render( ); const form = screen.getByRole("form"); assert.strictEqual(form.tagName, "DIV"); assert.strictEqual(form.getAttribute("id"), "custom-form"); }); });