Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: fix test case
  • Loading branch information
zombieJ committed Mar 6, 2025
commit 22192e4280cdde46698dc5ec187728f9f6c20ac9
17 changes: 7 additions & 10 deletions tests/Virtual.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { act, fireEvent, render } from '@testing-library/react';
import { _rs as onEsResize } from '@rc-component/resize-observer/es/utils/observerUtil';
import { _rs as onLibResize } from '@rc-component/resize-observer/lib/utils/observerUtil';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { resetWarned } from '@rc-component/util/lib/warning';
Expand All @@ -8,13 +7,14 @@ import { VirtualTable, type Reference, type VirtualTableProps } from '../src';

global.scrollToConfig = null;

jest.mock('rc-virtual-list', async () => {
const RealVirtualList = ((await jest.importActual('rc-virtual-list')) as any).default;
jest.mock('rc-virtual-list', () => {
const OriReact = jest.requireActual('react');
const RealVirtualList = jest.requireActual('rc-virtual-list').default;

const WrapperVirtualList = React.forwardRef((props: any, ref) => {
const myRef = React.useRef(null);
const WrapperVirtualList = OriReact.forwardRef((props: any, ref) => {
const myRef = OriReact.useRef(null);

React.useImperativeHandle(ref, () => ({
OriReact.useImperativeHandle(ref, () => ({
...myRef.current,
scrollTo: (config: any) => {
global.scrollToConfig = config;
Expand All @@ -25,9 +25,7 @@ jest.mock('rc-virtual-list', async () => {
return <RealVirtualList ref={myRef} {...props} data-scroll-width={props.scrollWidth} />;
});

return {
default: WrapperVirtualList,
};
return WrapperVirtualList;
});

describe('Table.Virtual', () => {
Expand Down Expand Up @@ -82,7 +80,6 @@ describe('Table.Virtual', () => {
function resize(target: HTMLElement) {
act(() => {
onLibResize([{ target } as any]);
onEsResize([{ target } as any]);
});
}

Expand Down