diff --git a/src/useForm.ts b/src/useForm.ts index 9d8b581b..1f90ad92 100644 --- a/src/useForm.ts +++ b/src/useForm.ts @@ -135,11 +135,15 @@ export class FormStore { }; private warningUnhooked = () => { - if (process.env.NODE_ENV !== 'production' && !this.formHooked) { - warning( - false, - 'Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?', - ); + if (process.env.NODE_ENV !== 'production') { + setTimeout(() => { + if (!this.formHooked) { + warning( + false, + 'Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?', + ); + } + }); } }; diff --git a/tests/index.test.js b/tests/index.test.js index e7fdac4b..778588d1 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -517,6 +517,7 @@ describe('Form.Basic', () => { }); it('warning if call function before set prop', () => { + jest.useFakeTimers(); resetWarned(); const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); @@ -529,10 +530,12 @@ describe('Form.Basic', () => { mount(); + jest.runAllTimers(); expect(errorSpy).toHaveBeenCalledWith( 'Warning: Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?', ); errorSpy.mockRestore(); + jest.useRealTimers(); }); it('filtering fields by meta', async () => {