diff --git a/components/form/__tests__/index.test.tsx b/components/form/__tests__/index.test.tsx
index 8b638e5d9c8a..c4f26cdf0e95 100644
--- a/components/form/__tests__/index.test.tsx
+++ b/components/form/__tests__/index.test.tsx
@@ -639,7 +639,7 @@ describe('Form', () => {
value = '',
id,
}) => {
- shouldRender();
+ shouldRender(value);
return ;
};
@@ -667,8 +667,10 @@ describe('Form', () => {
expect(formRef.current!.getFieldsValue()).toEqual({ light: 'bamboo' });
- expect(container.querySelector('#changed')!.value).toEqual('bamboo');
+ await waitFakeTimer();
+
expect(shouldNotRender).toHaveBeenCalledTimes(1);
+ expect(shouldRender).toHaveBeenLastCalledWith('bamboo');
expect(shouldRender).toHaveBeenCalledTimes(2);
});
diff --git a/components/modal/__tests__/hook.test.tsx b/components/modal/__tests__/hook.test.tsx
index cccb5420d7c2..16edbe4ac9a5 100644
--- a/components/modal/__tests__/hook.test.tsx
+++ b/components/modal/__tests__/hook.test.tsx
@@ -2,7 +2,7 @@ import CSSMotion from 'rc-motion';
import { genCSSMotion } from 'rc-motion/lib/CSSMotion';
import KeyCode from 'rc-util/lib/KeyCode';
import React from 'react';
-import TestUtils, { act } from 'react-dom/test-utils';
+import { act } from 'react-dom/test-utils';
import Modal from '..';
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
@@ -199,10 +199,6 @@ describe('Modal.hook', () => {
it('the callback close should be a method when onCancel has a close parameter', async () => {
jest.useFakeTimers();
- const clear = async function clear() {
- await waitFakeTimer();
- };
-
const mockFn = jest.fn();
const Demo = () => {
@@ -229,57 +225,57 @@ describe('Modal.hook', () => {
const { container } = render();
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// First open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Click mask to close
fireEvent.click(document.body.querySelectorAll('.ant-modal-wrap')[0]);
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// Second open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Press ESC to turn off
- TestUtils.Simulate.keyDown(document.body.querySelectorAll('.ant-modal')[0], {
+ fireEvent.keyDown(document.body.querySelectorAll('.ant-modal')[0], {
keyCode: KeyCode.ESC,
});
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// Third open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Click the close icon to close
fireEvent.click(document.body.querySelectorAll('.ant-modal-close')[0]);
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// Last open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Click the Cancel button to close (invalid)
fireEvent.click(document.body.querySelectorAll('.ant-modal-confirm-btns > .ant-btn')[0]);
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
@@ -288,7 +284,7 @@ describe('Modal.hook', () => {
// Click the Cancel button to close (valid)
fireEvent.click(document.body.querySelectorAll('.ant-modal-confirm-btns > .ant-btn')[0]);
- await clear();
+ await waitFakeTimer();
expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);