fix: testing act error (#36915)

* test: switch act from react-dom/test-utils to testing-library/react

* test: fix jest.runAllTimers usage with act

Co-authored-by: ian.xufeng <ian.xufeng@shopee.com>
This commit is contained in:
clean99 2022-08-05 18:27:08 +08:00 committed by GitHub
parent 73e541911b
commit 20a2bb3374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 10 deletions

View File

@ -26,7 +26,7 @@ describe('Upload.Dragger', () => {
},
});
await act(() => {
act(() => {
jest.runAllTimers();
});

View File

@ -322,7 +322,9 @@ describe('Upload', () => {
const { rerender } = render(<Upload ref={ref} />);
expect(ref.current.fileList).toEqual([]);
rerender(<Upload ref={ref} fileList={fileList} />);
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();
});

View File

@ -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);

View File

@ -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';