diff --git a/packages/components/cascader-panel/__tests__/cascader-panel.spec.ts b/packages/components/cascader-panel/__tests__/cascader-panel.spec.ts index da6a52f582..7f8b830f05 100644 --- a/packages/components/cascader-panel/__tests__/cascader-panel.spec.ts +++ b/packages/components/cascader-panel/__tests__/cascader-panel.spec.ts @@ -35,6 +35,11 @@ const NORMAL_OPTIONS = [ }, ], }, + { + value: 'guangdong', + label: 'Guangdong', + children: [], + }, ] const DISABLED_OPTIONS = [ @@ -154,12 +159,14 @@ describe('CascaderPanel.vue', () => { }) const options = wrapper.findAll(NODE) - const [bjNode, zjNode] = options + const [bjNode, zjNode, , gdNode] = options expect(wrapper.findAll(MENU).length).toBe(1) - expect(options.length).toBe(3) + expect(options.length).toBe(4) expect(bjNode.text()).toBe('Beijing') expect(bjNode.find(EXPAND_ARROW).exists()).toBe(false) + expect(zjNode.find(EXPAND_ARROW).exists()).toBe(true) + expect(gdNode.find(EXPAND_ARROW).exists()).toBe(false) await zjNode.trigger('click') const menus = wrapper.findAll(MENU) @@ -178,6 +185,12 @@ describe('CascaderPanel.vue', () => { expect(handleExpandChange).toBeCalledTimes(2) expect(handleChange).toBeCalledTimes(2) expect(wrapper.vm.value).toEqual(['beijing']) + + await gdNode.trigger('click') + expect(wrapper.findAll(MENU).length).toBe(1) + expect(handleExpandChange).toBeCalledTimes(3) + expect(handleChange).toBeCalledTimes(3) + expect(wrapper.vm.value).toEqual(['guangdong']) }) test('with default value', async () => { diff --git a/packages/components/cascader-panel/src/node.ts b/packages/components/cascader-panel/src/node.ts index 8ac9d016af..19ee4acec9 100644 --- a/packages/components/cascader-panel/src/node.ts +++ b/packages/components/cascader-panel/src/node.ts @@ -120,7 +120,7 @@ class Node { return isUndefined(isLeaf) ? lazy && !loaded ? false - : !Array.isArray(childrenData) + : !(Array.isArray(childrenData) && childrenData.length) : !!isLeaf }