Repository: react-hook-form/react-hook-form
File: src/useForm.test.tsx (TypeScript)

Code before:
      const mockReset = jest.spyOn(window.HTMLFormElement.prototype, 'reset');
      let methods: UseFormMethods;
      const Component = () => {
        methods = useForm();
        return <input name="test" ref={methods.register} />;
      };
      render(<Component />);

      actComponent(() => methods.reset());

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

    it('should set default value if values is specified to first argument', async () => {
      const { result } = renderHook(() => useForm());

      result.current.register('test');

      act(() => result.current.reset({ test: 'test' }));

      expect(result.current.control.defaultValuesRef.current).toEqual({
        test: 'test',
      });
    });

    it('should not reset unmountFieldsState value when shouldUnregister set to false ', () => {
      const { result } = renderHook(() => useForm());

      result.current.register('test');

      act(() => result.current.reset({ test: 'test' }));

      expect(result.current.control.unmountFieldsStateRef.current).toEqual({});
    });

    it('should execute resetFieldArrayFunctionRef if resetFieldArrayFunctionRef is exist', async () => {
      const { result } = renderHook(() => useForm());
      const reset = jest.fn();
      result.current.control.resetFieldArrayFunctionRef.current['test'] = reset;

      result.current.register('test');

      act(() => result.current.reset({ test: 'test' }));

      expect(reset).toHaveBeenCalled();
    });

    // TODO: fix to not use control
    it('should not reset if OmitResetState is specified', async () => {
      const { result } = renderHook(() => useForm());


Review comment (suggestion):
this test has not been able to test correctly.
You should check unmountFieldsStateRef after executed unmount() or unregister().

Code after:
      const mockReset = jest.spyOn(window.HTMLFormElement.prototype, 'reset');
      let methods: UseFormMethods;
      const Component = () => {
        methods = useForm();
        return <input name="test" ref={methods.register} />;
      };
      render(<Component />);

      actComponent(() => methods.reset());

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

    it('should set default value if values is specified to first argument', async () => {
      const { result } = renderHook(() => useForm());

      result.current.register('test');

      act(() => result.current.reset({ test: 'test' }));

      expect(result.current.control.defaultValuesRef.current).toEqual({
        test: 'test',
      });
    });

    it('should reset unmountFieldsState value when shouldUnregister set to false', () => {
      const { result } = renderHook(() =>
        useForm({
          shouldUnregister: false,
        }),
      );

      result.current.register('test');

      act(() => result.current.reset({ test: 'test' }));

      expect(result.current.control.unmountFieldsStateRef.current).toEqual({
        test: 'test',
      });
    });

    it('should not reset unmountFieldsState value by default', () => {
      const { result } = renderHook(() => useForm());

      result.current.register('test');

      act(() => result.current.reset({ test: 'test' }));

      expect(result.current.control.unmountFieldsStateRef.current).toEqual({});
    });