Skip to content

Commit

Permalink
Merge pull request #3 from atmina/add-form-state-test
Browse files Browse the repository at this point in the history
Add test for formState
  • Loading branch information
reiv authored Mar 25, 2023
2 parents ea0bc4a + 93ddce2 commit 03c037c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/formbuilder.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,33 @@ describe("useFormBuilder", () => {
expect(watchedFirstNameAlt).toHaveTextContent("Joe");
});
});

test("formState", async () => {
const harness = createHarness({ defaultValues }, (builder) => {
const isDirty = builder.formState.isDirty;

return (
<div data-testid="form-state-is-dirty">
{isDirty ? "true" : "false"}
</div>
);
});

render(<harness.Form />);

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");
});
});
});

0 comments on commit 03c037c

Please sign in to comment.