Skip to content

Commit

Permalink
test: fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Apr 25, 2024
1 parent 046507d commit df95443
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ import TreeSelect, { TreeNode } from '../src';
import focusTest from './shared/focusTest';
import { selectNode } from './util';

const mockScrollTo = jest.fn();

// Mock `useScrollTo` from `rc-virtual-list/lib/hooks/useScrollTo`
jest.mock('rc-virtual-list/lib/hooks/useScrollTo', () => {
return () => mockScrollTo;
});

describe('TreeSelect.basic', () => {
beforeEach(() => {
jest.useFakeTimers();
mockScrollTo.mockReset();
});

beforeAll(() => {
Expand Down Expand Up @@ -391,11 +399,8 @@ describe('TreeSelect.basic', () => {
wrapper.openSelect();
expect(wrapper.isOpen()).toBeFalsy();

/* const scrollTo = jest.fn();
wrapper.find('List').instance().scrollTo = scrollTo;
wrapper.openSelect();
expect(scrollTo).toHaveBeenCalled(); */
expect(mockScrollTo).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -525,7 +530,7 @@ describe('TreeSelect.basic', () => {

keyDown(KeyCode.DOWN);
expect(wrapper.find('.rc-tree-select-tree-treenode-active').text()).toBe('0 label');

keyDown(KeyCode.UP);
expect(wrapper.find('.rc-tree-select-tree-treenode-active').text()).toBe('11 label');
});
Expand Down

0 comments on commit df95443

Please sign in to comment.