test: fix ci (#55947)

* test: fix ci

* chore: simplify
This commit is contained in:
二货爱吃白萝卜
2025-11-27 16:24:43 +08:00
committed by GitHub
parent 06619d5010
commit 02669912b7
3 changed files with 32 additions and 11 deletions

View File

@@ -9,7 +9,7 @@ import excludeAllWarning from '../../../tests/shared/excludeWarning';
import focusTest from '../../../tests/shared/focusTest';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { fireEvent, render } from '../../../tests/utils';
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
import ConfigProvider from '../../config-provider';
const { SHOW_CHILD, SHOW_PARENT } = Cascader;
@@ -136,7 +136,7 @@ describe('Cascader', () => {
expect(onChange).toHaveBeenCalledWith(['zhejiang', 'hangzhou', 'xihu'], expect.anything());
});
it('backspace should work with `Cascader[showSearch]`', () => {
it('backspace should work with `Cascader[showSearch]`', async () => {
const { container } = render(<Cascader options={options} showSearch />);
fireEvent.change(container.querySelector('input')!, { target: { value: '123' } });
expect(isOpen(container)).toBeTruthy();
@@ -148,6 +148,7 @@ describe('Cascader', () => {
expect(isOpen(container)).toBeTruthy();
fireEvent.keyDown(container.querySelector('input')!, { key: 'Backspace', keyCode: 8 });
await waitFakeTimer();
expect(isOpen(container)).toBeFalsy();
});
@@ -500,11 +501,12 @@ describe('Cascader', () => {
expect(onChange).toHaveBeenCalledWith(['zhejiang', 'hangzhou', 'xihu'], expect.anything());
});
it('options should open after press esc and then search', () => {
it('options should open after press esc and then search', async () => {
const { container } = render(<Cascader options={options} showSearch />);
fireEvent.change(container.querySelector('input')!, { target: { value: 'jin' } });
expect(isOpen(container)).toBeTruthy();
fireEvent.keyDown(container.querySelector('input')!, { key: 'Esc', keyCode: 27 });
await waitFakeTimer();
expect(isOpen(container)).toBeFalsy();
fireEvent.change(container.querySelector('input')!, { target: { value: 'jin' } });
expect(isOpen(container)).toBeTruthy();

View File

@@ -138,7 +138,7 @@
"@rc-component/rate": "~1.0.0",
"@rc-component/resize-observer": "^1.0.1",
"@rc-component/segmented": "~1.2.3",
"@rc-component/select": "~1.2.2",
"@rc-component/select": "~1.2.3",
"@rc-component/slider": "~1.0.0",
"@rc-component/steps": "~1.2.2",
"@rc-component/switch": "~1.0.2",

View File

@@ -96,13 +96,32 @@ global.requestAnimationFrame = global.requestAnimationFrame || global.setTimeout
global.cancelAnimationFrame = global.cancelAnimationFrame || global.clearTimeout;
if (typeof MessageChannel === 'undefined') {
(global as any).MessageChannel = function MockMessageChannel() {
const port1: any = {};
const port2: any = {};
port1.postMessage = port2.onmessage = () => {};
port2.postMessage = port1.onmessage = () => {};
return { port1, port2 };
};
(global as any).MessageChannel = class {
port1: any;
port2: any;
constructor() {
const createPort = (): any => {
const port: any = {
onmessage: null,
postMessage: (message: any) => {
setTimeout(() => {
port._target?.onmessage?.({ data: message });
}, 0);
},
_target: null,
};
return port;
};
const port1 = createPort();
const port2 = createPort();
port1._target = port2;
port2._target = port1;
this.port1 = port1;
this.port2 = port2;
}
} as any;
}
// Mock useId to return a stable id for snapshot testing