data-testid is not recognised in test file after wrapping with controller?

Viewed 1093

Hi i am having a input field in a component which is wrapped with controller from react-hook-form and that input field is wrapped with react-input-mask for masking.Before wrapping the input field with controller the data-test-id works well . After wrapping it cant able to find it. Here i am sharing the input field compponent and test file for that.Please help me with that.

             <Controller
                      name="dob"
                      control={control}
                      as={
                        <InputMask mask="9999-99-99" >
                          {() => (
                            <TextField
                              id="inputfive"
                              name="dob"
                              label={t("TXT.YOUR_LOAN_DETAIL_PAGE.DOB")}
                              placeholder={t("TXT.YOUR_LOAN_DETAIL_PAGE.DOB")}
                              data-testid="dob-input"
                            />
                          )}
                        </InputMask>
                      }
                      rules={{
                        required: "this is required",
                        pattern: {
                          value: /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/,
                          message: "Please Enter a correct pattern"
                        }
                      }}
                    />

In test file:

it("should not sumbit the form", async () => {
  const onSubmit = jest.fn();
  const { getByText, getByTestId } = render(<LinkApplication onSubmit={onSubmit} />);

  const Dob_Input = getByTestId("dob-input");
  const form = getByTestId("form");
  act(() => {
    fireEvent.change(  Dob_Input , {
      target: { value: "1995-09" }
    });
  });
  expect(Dob_Input.value).toBe("1995-09");


  await act(() => {
    fireEvent.submit(form);
  });

expect(onSubmit).not.toHaveBeenCalled();
});

Error:

Unable to find an element by: [data-testid="dob-input"]

0 Answers
Related