fix(components): [el-cascader] empty children set leaf (#3758)

* fix(components): [el-cascader] empty children set leaf

* test: add test
This commit is contained in:
btea 2021-11-05 19:50:48 -05:00 committed by GitHub
parent e9a110ed47
commit c6c1e965f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -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 () => {

View File

@ -120,7 +120,7 @@ class Node {
return isUndefined(isLeaf)
? lazy && !loaded
? false
: !Array.isArray(childrenData)
: !(Array.isArray(childrenData) && childrenData.length)
: !!isLeaf
}