diff --git a/src/OptionList/useActive.ts b/src/OptionList/useActive.ts
index 7bf02724..849f9bfb 100644
--- a/src/OptionList/useActive.ts
+++ b/src/OptionList/useActive.ts
@@ -18,7 +18,7 @@ export default (
React.useEffect(
() => {
- if (open && !multiple) {
+ if (!multiple) {
setActiveValueCells(firstValueCells || []);
}
},
diff --git a/tests/selector.spec.tsx b/tests/selector.spec.tsx
index 3b20e6c9..840ca194 100644
--- a/tests/selector.spec.tsx
+++ b/tests/selector.spec.tsx
@@ -1,18 +1,58 @@
import React, { useState } from 'react';
+import { fireEvent, render } from '@testing-library/react';
import { mount } from './enzyme';
import Cascader from '../src';
import { addressOptions } from './demoOptions';
+// Mock `useActive` hook
+jest.mock('../src/OptionList/useActive', () => (multiple: boolean, open: boolean) => {
+ // Pass to origin hooks
+ const originHook = jest.requireActual('../src/OptionList/useActive').default;
+ const [activeValueCells, setActiveValueCells] = originHook(multiple, open);
+
+ global.activeValueCells = activeValueCells;
+
+ return [activeValueCells, setActiveValueCells];
+});
+
describe('Cascader.Selector', () => {
describe('clear all', () => {
it('single', () => {
const onChange = jest.fn();
- const wrapper = mount();
+ const { container } = render(
+ ,
+ );
- wrapper.find('.rc-cascader-clear-icon').simulate('mouseDown');
+ fireEvent.mouseDown(container.querySelector('.rc-cascader-clear-icon'));
expect(onChange).toHaveBeenCalledWith(undefined, undefined);
});
+ it('Should clear activeCells', () => {
+ const onChange = jest.fn();
+
+ const { container } = render(
+ ,
+ );
+
+ // Open and select
+ fireEvent.mouseDown(container.querySelector('.rc-cascader-selector'));
+ expect(container.querySelector('.rc-cascader-open')).toBeTruthy();
+
+ fireEvent.click(container.querySelector('.rc-cascader-menu-item-content'));
+ fireEvent.click(container.querySelectorAll('.rc-cascader-menu-item-content')[1]);
+ expect(container.querySelector('.rc-cascader-open')).toBeFalsy();
+
+ // Clear
+ fireEvent.mouseDown(container.querySelector('.rc-cascader-clear-icon'));
+ expect(global.activeValueCells).toEqual([]);
+ });
+
it('multiple', () => {
const onChange = jest.fn();
const wrapper = mount(