import { describe, bench } from "vitest"; import { Field, Form } from "houseform"; import { z } from "zod"; import { cleanup, fireEvent, getByTestId, render, } from "@testing-library/react"; import { Formik, Field as FormikField } from "formik"; import { toFormikValidationSchema } from "zod-formik-adapter"; import { FieldProps } from "formik/dist/Field"; import { Controller, useForm } from "react-hook-form"; import React, { useState } from "react"; import { zodResolver } from "@hookform/resolvers/zod"; const arr = Array.from({ length: 1000 }, (_, i) => i); function HouseFormOnMountBenchmark() { return (
{() => ( <> {arr.map((num, i) => { return ( {({ value, setValue, onBlur, errors }) => { return (
setValue(e.target.valueAsNumber)} placeholder={`Number ${i}`} /> {errors.map((error) => (

{error}

))}
); }}
); })} )}
); } function FormikOnMountBenchmark() { return ( {}} > {() => ( <> {arr.map((num, i) => ( {(props: FieldProps) => (
{props.meta.error}
)}
))} )}
); } describe("Validates onMount on 1,000 form items", () => { bench( "HouseForm", async () => { const { findAllByText } = render(); await findAllByText("Must be at least three"); }, { setup(task) { task.opts.beforeEach = () => { cleanup(); }; }, } ); bench( "Formik", async () => { const { findAllByText } = render(); await findAllByText("Must be at least three"); }, { setup(task) { task.opts.beforeEach = () => { cleanup(); }; }, } ); // Does not support this feature bench.todo("React Hook Form"); bench.todo("React Hook Form (Headless)"); });