Testing react-hook-form's Controller API using enzyme / Jest

732 Views Asked by At

Is there a way to test a component that uses react-hook-form's Controller API using Jest/enzyme?

Kindly take a look at this code sandbox to see what my component looks like

I did try mocking Controller using the below for a snapshot test;

jest.mock('react-hook-form', () => ({
  Controller: () => (<></>),
  useForm: () => ({
    control: () => ({}),
    handleSubmit: () => jest.fn(),
  }),
}))

But then the inputs are not rendered because the mocked Controller would return null (because of the <></>).

Any idea how to go about this, or must I use testing library to have a chance at writing a test for this?

0

There are 0 best solutions below