diff --git a/components/upload/__tests__/dragger.test.js b/components/upload/__tests__/dragger.test.js index 645cdbddd2..b987555a9e 100644 --- a/components/upload/__tests__/dragger.test.js +++ b/components/upload/__tests__/dragger.test.js @@ -26,7 +26,7 @@ describe('Upload.Dragger', () => { }, }); - await act(() => { + act(() => { jest.runAllTimers(); }); diff --git a/components/upload/__tests__/upload.test.js b/components/upload/__tests__/upload.test.js index 042b85cd87..222d8aa94c 100644 --- a/components/upload/__tests__/upload.test.js +++ b/components/upload/__tests__/upload.test.js @@ -322,7 +322,9 @@ describe('Upload', () => { const { rerender } = render(); expect(ref.current.fileList).toEqual([]); rerender(); - jest.runAllTimers(); + act(() => { + jest.runAllTimers(); + }); expect(ref.current.fileList).toEqual(fileList); jest.useRealTimers(); }); @@ -725,7 +727,7 @@ describe('Upload', () => { await Promise.resolve(); } }); - await act(() => { + act(() => { jest.runAllTimers(); }); await act(async () => { @@ -945,7 +947,7 @@ describe('Upload', () => { }); // Motion leave status change: start > active - await act(() => { + act(() => { jest.runAllTimers(); }); diff --git a/components/upload/__tests__/uploadlist.test.js b/components/upload/__tests__/uploadlist.test.js index 3b018211d7..4d6876c7a3 100644 --- a/components/upload/__tests__/uploadlist.test.js +++ b/components/upload/__tests__/uploadlist.test.js @@ -263,7 +263,7 @@ describe('Upload List', () => { // Error message fireEvent.mouseEnter(wrapper.querySelector('.ant-upload-list-item')); - await act(() => { + act(() => { jest.runAllTimers(); }); @@ -574,7 +574,9 @@ describe('Upload List', () => { />, ); - jest.runAllTimers(); + act(() => { + jest.runAllTimers(); + }); unmount(); @@ -1138,7 +1140,7 @@ describe('Upload List', () => { expect(onChange).toHaveBeenCalled(); // Check for images - await act(() => { + act(() => { jest.runAllTimers(); }); const afterImgNode = wrapper.container.querySelectorAll( @@ -1313,7 +1315,7 @@ describe('Upload List', () => { expect(uploadRef.current.fileList).toHaveLength(fileNames.length); - await act(() => { + act(() => { jest.runAllTimers(); }); expect(uploadRef.current.fileList).toHaveLength(fileNames.length); diff --git a/tests/utils.ts b/tests/utils.ts index abba119713..6a969070fc 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -1,9 +1,8 @@ import MockDate from 'mockdate'; import type { ReactElement } from 'react'; import { StrictMode } from 'react'; -import { act } from 'react-dom/test-utils'; import type { RenderOptions } from '@testing-library/react'; -import { render } from '@testing-library/react'; +import { render, act } from '@testing-library/react'; import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil'; import { _rs as onEsResize } from 'rc-resize-observer/es/utils/observerUtil';