Skip to content

Commit 51db9fb

Browse files
authored
chore: move warning delay (#116)
1 parent 17c8061 commit 51db9fb

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/useForm.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,15 @@ export class FormStore {
135135
};
136136

137137
private warningUnhooked = () => {
138-
if (process.env.NODE_ENV !== 'production' && !this.formHooked) {
139-
warning(
140-
false,
141-
'Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?',
142-
);
138+
if (process.env.NODE_ENV !== 'production') {
139+
setTimeout(() => {
140+
if (!this.formHooked) {
141+
warning(
142+
false,
143+
'Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?',
144+
);
145+
}
146+
});
143147
}
144148
};
145149

tests/index.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ describe('Form.Basic', () => {
517517
});
518518

519519
it('warning if call function before set prop', () => {
520+
jest.useFakeTimers();
520521
resetWarned();
521522
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
522523

@@ -529,10 +530,12 @@ describe('Form.Basic', () => {
529530

530531
mount(<Test />);
531532

533+
jest.runAllTimers();
532534
expect(errorSpy).toHaveBeenCalledWith(
533535
'Warning: Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?',
534536
);
535537
errorSpy.mockRestore();
538+
jest.useRealTimers();
536539
});
537540

538541
it('filtering fields by meta', async () => {

0 commit comments

Comments
 (0)