Browse Source

test: Update table test sleep -> useFakeTimers (#37914)

* feat:update table test sleep -> useFakeTimers

* test: tabel test case waitFakeTimer(500) -> waitFakeTimer()
pull/37927/head
hms181231 2 years ago
committed by GitHub
parent
commit
1928f10b69
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      components/table/__tests__/Table.test.tsx

12
components/table/__tests__/Table.test.tsx

@ -3,7 +3,7 @@ import type { TableProps } from '..';
import Table from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { fireEvent, render, sleep } from '../../../tests/utils';
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
const { Column, ColumnGroup } = Table;
@ -70,6 +70,7 @@ describe('Table', () => {
});
it('loading with Spin', async () => {
jest.useFakeTimers();
const loading = {
spinning: false,
delay: 500,
@ -81,19 +82,24 @@ describe('Table', () => {
loading.spinning = true;
rerender(<Table loading={loading} />);
expect(container.querySelectorAll('.ant-spin')).toHaveLength(0);
await sleep(500);
await waitFakeTimer();
rerender(<Table loading />);
expect(container.querySelectorAll('.ant-spin')).toHaveLength(1);
jest.clearAllTimers();
jest.useRealTimers();
});
// https://github.com/ant-design/ant-design/issues/22733
it('support loading tip', async () => {
jest.useFakeTimers();
const { container, rerender } = render(<Table loading={{ tip: 'loading...' }} />);
await sleep(500);
await waitFakeTimer();
rerender(
<Table loading={{ tip: 'loading...', loading: true } as TableProps<any>['loading']} />,
);
expect(container.querySelectorAll('.ant-spin')).toHaveLength(1);
jest.clearAllTimers();
jest.useRealTimers();
});
it('props#columnsPageRange and props#columnsPageSize do not warn anymore', () => {

Loading…
Cancel
Save