Skip to content

Commit 06a5e3b

Browse files
author
DuQi
committed
test: cover load switcher after clearing search
1 parent bb13fc8 commit 06a5e3b

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/OptionList.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
326326

327327
const hasLoadDataFn = useMemo(
328328
() => (searchValue ? false : true),
329-
// eslint-disable-next-line react-hooks/exhaustive-deps
330-
[searchValue, treeExpandedKeys || expandedKeys],
329+
[searchValue],
331330
([preSearchValue], [nextSearchValue]) => preSearchValue !== nextSearchValue,
332331
);
333332

tests/Select.loadData.spec.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('TreeSelect.loadData', () => {
4444
}
4545
});
4646

47-
it('keeps load switcher after clearing search value', () => {
47+
it('keeps load switcher after clearing search value', async () => {
4848
const loadData = jest.fn(() => Promise.resolve());
4949
const { container } = render(
5050
<TreeSelect
@@ -66,5 +66,12 @@ describe('TreeSelect.loadData', () => {
6666
expect(loadData).not.toHaveBeenCalled();
6767
expect(container.querySelector('.rc-tree-select-tree-switcher_close')).toBeTruthy();
6868
expect(container.querySelector('.rc-tree-select-tree-switcher-noop')).toBeFalsy();
69+
70+
fireEvent.click(container.querySelector('.rc-tree-select-tree-switcher_close')!);
71+
await act(async () => {
72+
await Promise.resolve();
73+
});
74+
75+
expect(loadData).toHaveBeenCalledTimes(1);
6976
});
7077
});

0 commit comments

Comments
 (0)