fix(utils): [vnode] flattedChildren support subTree (#10298)

This commit is contained in:
Xc
2022-10-31 16:21:50 +08:00
committed by GitHub
parent deccb07f1f
commit b45346cc93
2 changed files with 30 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { nextTick, ref } from 'vue'
import { defineComponent, nextTick, ref } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, test, vi } from 'vitest'
import { EVENT_CODE } from '@element-plus/constants'
@@ -8,6 +8,19 @@ import TabNav from '../src/tab-nav'
import type { TabPaneName } from '../src/tabs'
import type { TabsPaneContext } from '@element-plus/tokens'
const Comp = defineComponent({
components: {
TabPane,
},
setup() {
return () => (
<TabPane name="tab1" label="tab1">
Tab 1 content
</TabPane>
)
},
})
describe('Tabs.vue', () => {
test('create', async () => {
const wrapper = mount(() => (
@@ -754,4 +767,17 @@ describe('Tabs.vue', () => {
expect(navItemsWrapper[2].classes('is-active')).toBe(true)
expect(navItemsWrapper[3].classes('is-active')).toBe(false)
})
test('tab-pane nested', async () => {
const wrapper = mount(() => (
<Tabs>
<Comp />
</Tabs>
))
const panesWrapper = wrapper.findAllComponents(TabPane)
await nextTick()
expect(panesWrapper.length).toBe(1)
})
})

View File

@@ -159,6 +159,9 @@ export const flattedChildren = (
result.push(...flattedChildren(child.children))
} else {
result.push(child)
if (isVNode(child) && child.component?.subTree) {
result.push(...flattedChildren(child.component.subTree))
}
}
})
return result