Skip to content

Commit cf93845

Browse files
committed
wip: save
1 parent ccbb170 commit cf93845

File tree

1 file changed

+102
-83
lines changed

1 file changed

+102
-83
lines changed

packages/runtime-vapor/__tests__/customElement.spec.ts

Lines changed: 102 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,91 +1574,110 @@ describe('defineVaporCustomElement', () => {
15741574
app.unmount()
15751575
})
15761576

1577-
// test('toggle nested custom element with shadowRoot: false', async () => {
1578-
// customElements.define(
1579-
// 'my-el-child-shadow-false',
1580-
// defineVaporCustomElement(
1581-
// {
1582-
// render(ctx: any) {
1583-
// return h('div', null, [renderSlot(ctx.$slots, 'default')])
1584-
// },
1585-
// },
1586-
// { shadowRoot: false },
1587-
// ),
1588-
// )
1589-
// const ChildWrapper = {
1590-
// render() {
1591-
// return h('my-el-child-shadow-false', null, 'child')
1592-
// },
1593-
// }
1594-
1595-
// customElements.define(
1596-
// 'my-el-parent-shadow-false',
1597-
// defineVaporCustomElement(
1598-
// {
1599-
// props: {
1600-
// isShown: { type: Boolean, required: true },
1601-
// },
1602-
// render(ctx: any, _: any, $props: any) {
1603-
// return $props.isShown
1604-
// ? h('div', { key: 0 }, [renderSlot(ctx.$slots, 'default')])
1605-
// : null
1606-
// },
1607-
// },
1608-
// { shadowRoot: false },
1609-
// ),
1610-
// )
1611-
// const ParentWrapper = {
1612-
// props: {
1613-
// isShown: { type: Boolean, required: true },
1614-
// },
1615-
// render(ctx: any, _: any, $props: any) {
1616-
// return h('my-el-parent-shadow-false', { isShown: $props.isShown }, [
1617-
// renderSlot(ctx.$slots, 'default'),
1618-
// ])
1619-
// },
1620-
// }
1621-
1622-
// const isShown = ref(true)
1623-
// const App = {
1624-
// render() {
1625-
// return h(ParentWrapper, { isShown: isShown.value } as any, {
1626-
// default: () => [h(ChildWrapper)],
1627-
// })
1628-
// },
1629-
// }
1630-
// const container = document.createElement('div')
1631-
// document.body.appendChild(container)
1632-
// const app = createVaporApp(App)
1633-
// app.mount(container)
1634-
// expect(container.innerHTML).toBe(
1635-
// `<my-el-parent-shadow-false is-shown="" data-v-app="">` +
1636-
// `<div>` +
1637-
// `<my-el-child-shadow-false data-v-app="">` +
1638-
// `<div>child</div>` +
1639-
// `</my-el-child-shadow-false>` +
1640-
// `</div>` +
1641-
// `</my-el-parent-shadow-false>`,
1642-
// )
1577+
test('toggle nested custom element with shadowRoot: false', async () => {
1578+
customElements.define(
1579+
'my-el-child-shadow-false',
1580+
defineVaporCustomElement(
1581+
{
1582+
setup() {
1583+
const n0 = template('<div></div>')() as any
1584+
setInsertionState(n0, null)
1585+
createSlot('default', null)
1586+
return n0
1587+
},
1588+
},
1589+
{ shadowRoot: false } as any,
1590+
),
1591+
)
1592+
const ChildWrapper = {
1593+
setup() {
1594+
return createComponentWithFallback('my-el-child-shadow-false', null, {
1595+
default: () => template('child')(),
1596+
})
1597+
},
1598+
}
16431599

1644-
// isShown.value = false
1645-
// await nextTick()
1646-
// expect(container.innerHTML).toBe(
1647-
// `<my-el-parent-shadow-false data-v-app=""><!----></my-el-parent-shadow-false>`,
1648-
// )
1600+
customElements.define(
1601+
'my-el-parent-shadow-false',
1602+
defineVaporCustomElement(
1603+
{
1604+
props: {
1605+
isShown: { type: Boolean, required: true },
1606+
},
1607+
setup(props: any) {
1608+
return createIf(
1609+
() => props.isShown,
1610+
() => {
1611+
const n0 = template('<div></div>')() as any
1612+
setInsertionState(n0, null)
1613+
createSlot('default', null)
1614+
return n0
1615+
},
1616+
)
1617+
},
1618+
},
1619+
{ shadowRoot: false } as any,
1620+
),
1621+
)
1622+
const ParentWrapper = {
1623+
props: {
1624+
isShown: { type: Boolean, required: true },
1625+
},
1626+
setup(props: any) {
1627+
return createComponentWithFallback(
1628+
'my-el-parent-shadow-false',
1629+
{ isShown: () => props.isShown },
1630+
{
1631+
default: () => createSlot('default'),
1632+
},
1633+
)
1634+
},
1635+
}
16491636

1650-
// isShown.value = true
1651-
// await nextTick()
1652-
// expect(container.innerHTML).toBe(
1653-
// `<my-el-parent-shadow-false data-v-app="" is-shown="">` +
1654-
// `<div>` +
1655-
// `<my-el-child-shadow-false data-v-app="">` +
1656-
// `<div>child</div>` +
1657-
// `</my-el-child-shadow-false>` +
1658-
// `</div>` +
1659-
// `</my-el-parent-shadow-false>`,
1660-
// )
1661-
// })
1637+
const isShown = ref(true)
1638+
const App = {
1639+
setup() {
1640+
return createComponent(
1641+
ParentWrapper,
1642+
{ isShown: () => isShown.value },
1643+
{
1644+
default: () => createComponent(ChildWrapper),
1645+
},
1646+
)
1647+
},
1648+
}
1649+
const container = document.createElement('div')
1650+
document.body.appendChild(container)
1651+
const app = createVaporApp(App)
1652+
app.mount(container)
1653+
expect(container.innerHTML).toBe(
1654+
`<my-el-parent-shadow-false is-shown="">` +
1655+
`<div>` +
1656+
`<my-el-child-shadow-false>` +
1657+
`<div>child<!--slot--></div>` +
1658+
`</my-el-child-shadow-false><!--slot--><!--slot-->` +
1659+
`</div><!--if-->` +
1660+
`</my-el-parent-shadow-false>`,
1661+
)
1662+
1663+
isShown.value = false
1664+
await nextTick()
1665+
expect(container.innerHTML).toBe(
1666+
`<my-el-parent-shadow-false><!--if--></my-el-parent-shadow-false>`,
1667+
)
1668+
1669+
isShown.value = true
1670+
await nextTick()
1671+
expect(container.innerHTML).toBe(
1672+
`<my-el-parent-shadow-false is-shown="">` +
1673+
`<div>` +
1674+
`<my-el-child-shadow-false>` +
1675+
`<div>child<!--slot--></div>` +
1676+
`</my-el-child-shadow-false><!--slot--><!--slot-->` +
1677+
`</div><!--if-->` +
1678+
`</my-el-parent-shadow-false>`,
1679+
)
1680+
})
16621681
})
16631682

16641683
// describe('helpers', () => {

0 commit comments

Comments
 (0)