Skip to content

react hook form testing isValid always false #9699

Answered by leapful
Santosl2 asked this question in Q&A
Discussion options

You must be logged in to vote

@Santosl2

Your jest.setup.ts file for finding option value is not correct because option value is number but data from select element is string. It should be:

jest.setup.ts, line 15

const option = options.find(
        (op) => `${op.value}` === event.currentTarget.value
      );

Furthermore, formState.isValid is a proxy object therefore it will be updated in next re-rendering, so a custom wait should be applied in order to get update formState value.

index.test.ts

describe("Home", () => {
  it("button must be enabled when user select your option", async () => {
    render(<Home />);

    expect(screen.getByText("Continue")).toBeDisabled();

    const input = screen.getByTestId("select");…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Santosl2
Comment options

@Santosl2
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Santosl2
Comment options

Answer selected by leapful
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants