Having a basic component which uses react-hook-form:
const { handleSubmit, reset, control } = useForm({ resolver: yupResolver(schema) });
...
<MyComponent
title='title'
open={isOpened}
control={control}
/>
This component has 3 props, title - a string, open - a function, control - no idea what is it, all of them mandatory.
So, when writing a test for it I got stuck here:
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
import MyComponent from './my-component';
describe('MyComponent', () => {
const title = 'title';
it('should render successfully', () => {
const { baseElement, getByText } = render(
<TaskModal
title={title}
open={jest.fn()}
control={} // what should be written here?
/>
);
expect(baseElement).toBeTruthy();
expect(getByText(title)).toBeTruthy();
});
How can control
be mocked for this test?
control
come from? You should at least provide where the control variable is defined or imported from what module – Flaxseed