diff --git a/src/formbuilder.test.tsx b/src/formbuilder.test.tsx index 94e61b4..cb0a4e5 100644 --- a/src/formbuilder.test.tsx +++ b/src/formbuilder.test.tsx @@ -149,4 +149,33 @@ describe("useFormBuilder", () => { expect(watchedFirstNameAlt).toHaveTextContent("Joe"); }); }); + + test("formState", async () => { + const harness = createHarness({ defaultValues }, (builder) => { + const isDirty = builder.formState.isDirty; + + return ( +
+ {isDirty ? "true" : "false"} +
+ ); + }); + + render(); + + const firstNameInput = screen.getByLabelText("first-name-input"); + + const formStateIsDirty = screen.getByTestId("form-state-is-dirty"); + + expect(formStateIsDirty).toHaveTextContent("false"); + + await act(async () => { + await userEvent.clear(firstNameInput); + await userEvent.type(firstNameInput, "Joe"); + }); + + await waitFor(() => { + expect(formStateIsDirty).toHaveTextContent("true"); + }); + }); });