mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
chore: merge maste
This commit is contained in:
commit
2a754bd5ca
@ -3,7 +3,7 @@ import type { InternalAffixClass } from '..';
|
||||
import Affix from '..';
|
||||
import accessibilityTest from '../../../tests/shared/accessibilityTest';
|
||||
import rtlTest from '../../../tests/shared/rtlTest';
|
||||
import { render, sleep, triggerResize } from '../../../tests/utils';
|
||||
import { render, sleep, triggerResize, waitFakeTimer } from '../../../tests/utils';
|
||||
import Button from '../../button';
|
||||
import { getObserverEntities } from '../utils';
|
||||
|
||||
@ -216,22 +216,31 @@ describe('Affix Render', () => {
|
||||
});
|
||||
|
||||
// Trigger inner and outer element for the two <ResizeObserver>s.
|
||||
it.each([
|
||||
{ selector: '.ant-btn' }, // inner
|
||||
{ selector: '.fixed' }, // outer
|
||||
])('trigger listener when size change', async ({ selector }) => {
|
||||
const updateCalled = jest.fn();
|
||||
const { container } = render(
|
||||
<AffixMounter offsetBottom={0} onTestUpdatePosition={updateCalled} />,
|
||||
{
|
||||
container: document.getElementById('mounter')!,
|
||||
},
|
||||
);
|
||||
[
|
||||
'.ant-btn', // inner
|
||||
'.fixed', // outer
|
||||
].forEach(selector => {
|
||||
it(`trigger listener when size change: ${selector}`, async () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
updateCalled.mockReset();
|
||||
triggerResize(container.querySelector(selector)!);
|
||||
await sleep(20);
|
||||
expect(updateCalled).toHaveBeenCalled();
|
||||
const updateCalled = jest.fn();
|
||||
const { container } = render(
|
||||
<AffixMounter offsetBottom={0} onTestUpdatePosition={updateCalled} />,
|
||||
{
|
||||
container: document.getElementById('mounter')!,
|
||||
},
|
||||
);
|
||||
|
||||
updateCalled.mockReset();
|
||||
triggerResize(container.querySelector(selector)!);
|
||||
|
||||
await waitFakeTimer();
|
||||
|
||||
expect(updateCalled).toHaveBeenCalled();
|
||||
|
||||
jest.clearAllTimers();
|
||||
jest.useRealTimers();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ import TreeSelect from '../../tree-select';
|
||||
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
import rtlTest from '../../../tests/shared/rtlTest';
|
||||
import { fireEvent, render, sleep, act } from '../../../tests/utils';
|
||||
import { fireEvent, render, sleep, act, waitFakeTimer } from '../../../tests/utils';
|
||||
import ConfigProvider from '../../config-provider';
|
||||
import Drawer from '../../drawer';
|
||||
import zhCN from '../../locale/zh_CN';
|
||||
@ -811,13 +811,7 @@ describe('Form', () => {
|
||||
fireEvent.submit(container.querySelector('form')!);
|
||||
|
||||
// Repeat enough time for validator promise sequence
|
||||
for (let i = 0; i < 20; i += 1) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await act(async () => {
|
||||
await Promise.resolve();
|
||||
jest.advanceTimersByTime(1000);
|
||||
});
|
||||
}
|
||||
await waitFakeTimer();
|
||||
|
||||
expect(container.querySelector('.ant-form-item-explain')?.textContent).toEqual('请输入Bamboo');
|
||||
|
||||
@ -1415,6 +1409,8 @@ describe('Form', () => {
|
||||
});
|
||||
|
||||
it('Form.Item.useStatus should work', async () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
const {
|
||||
Item: { useStatus },
|
||||
} = Form;
|
||||
@ -1461,11 +1457,16 @@ describe('Form', () => {
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Form.Item.useStatus should be used under Form.Item component.'),
|
||||
);
|
||||
|
||||
fireEvent.click(container.querySelector('.submit-button')!);
|
||||
await sleep(0);
|
||||
await waitFakeTimer();
|
||||
|
||||
expect(container.querySelector('.custom-input-required')?.classList).toContain(
|
||||
'custom-input-status-error',
|
||||
);
|
||||
|
||||
jest.clearAllTimers();
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('item customize margin', async () => {
|
||||
|
@ -64,3 +64,20 @@ export const triggerResize = (target: Element) => {
|
||||
|
||||
target.getBoundingClientRect = originGetBoundingClientRect;
|
||||
};
|
||||
|
||||
export async function waitFakeTimer(advanceTime = 1000) {
|
||||
for (let i = 0; i < 20; i += 1) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await act(async () => {
|
||||
await Promise.resolve();
|
||||
|
||||
if (advanceTime > 0) {
|
||||
jest.advanceTimersByTime(advanceTime);
|
||||
} else {
|
||||
jest.runAllTimers();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export * from '@testing-library/react';
|
||||
|
Loading…
Reference in New Issue
Block a user