|
|
@@ -10,6 +10,7 @@ import {
|
|
|
h,
|
|
|
inject,
|
|
|
nextTick,
|
|
|
+ provide,
|
|
|
ref,
|
|
|
render,
|
|
|
renderSlot,
|
|
|
@@ -1032,4 +1033,88 @@ describe('defineCustomElement', () => {
|
|
|
).toHaveBeenWarned()
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ test('async & nested custom elements', async () => {
|
|
|
+ let fooVal: string | undefined = ''
|
|
|
+ const E = defineCustomElement(
|
|
|
+ defineAsyncComponent(() => {
|
|
|
+ return Promise.resolve({
|
|
|
+ setup(props) {
|
|
|
+ provide('foo', 'foo')
|
|
|
+ },
|
|
|
+ render(this: any) {
|
|
|
+ return h('div', null, [renderSlot(this.$slots, 'default')])
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }),
|
|
|
+ )
|
|
|
+
|
|
|
+ const EChild = defineCustomElement({
|
|
|
+ setup(props) {
|
|
|
+ fooVal = inject('foo')
|
|
|
+ },
|
|
|
+ render(this: any) {
|
|
|
+ return h('div', null, 'child')
|
|
|
+ },
|
|
|
+ })
|
|
|
+ customElements.define('my-el-async-nested-ce', E)
|
|
|
+ customElements.define('slotted-child', EChild)
|
|
|
+ container.innerHTML = `<my-el-async-nested-ce><div><slotted-child></slotted-child></div></my-el-async-nested-ce>`
|
|
|
+
|
|
|
+ await new Promise(r => setTimeout(r))
|
|
|
+ const e = container.childNodes[0] as VueElement
|
|
|
+ expect(e.shadowRoot!.innerHTML).toBe(`<div><slot></slot></div>`)
|
|
|
+ expect(fooVal).toBe('foo')
|
|
|
+ })
|
|
|
+
|
|
|
+ test('async & multiple levels of nested custom elements', async () => {
|
|
|
+ let fooVal: string | undefined = ''
|
|
|
+ let barVal: string | undefined = ''
|
|
|
+ const E = defineCustomElement(
|
|
|
+ defineAsyncComponent(() => {
|
|
|
+ return Promise.resolve({
|
|
|
+ setup(props) {
|
|
|
+ provide('foo', 'foo')
|
|
|
+ },
|
|
|
+ render(this: any) {
|
|
|
+ return h('div', null, [renderSlot(this.$slots, 'default')])
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }),
|
|
|
+ )
|
|
|
+
|
|
|
+ const EChild = defineCustomElement({
|
|
|
+ setup(props) {
|
|
|
+ provide('bar', 'bar')
|
|
|
+ },
|
|
|
+ render(this: any) {
|
|
|
+ return h('div', null, [renderSlot(this.$slots, 'default')])
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const EChild2 = defineCustomElement({
|
|
|
+ setup(props) {
|
|
|
+ fooVal = inject('foo')
|
|
|
+ barVal = inject('bar')
|
|
|
+ },
|
|
|
+ render(this: any) {
|
|
|
+ return h('div', null, 'child')
|
|
|
+ },
|
|
|
+ })
|
|
|
+ customElements.define('my-el-async-nested-m-ce', E)
|
|
|
+ customElements.define('slotted-child-m', EChild)
|
|
|
+ customElements.define('slotted-child2-m', EChild2)
|
|
|
+ container.innerHTML =
|
|
|
+ `<my-el-async-nested-m-ce>` +
|
|
|
+ `<div><slotted-child-m>` +
|
|
|
+ `<slotted-child2-m></slotted-child2-m>` +
|
|
|
+ `</slotted-child-m></div>` +
|
|
|
+ `</my-el-async-nested-m-ce>`
|
|
|
+
|
|
|
+ await new Promise(r => setTimeout(r))
|
|
|
+ const e = container.childNodes[0] as VueElement
|
|
|
+ expect(e.shadowRoot!.innerHTML).toBe(`<div><slot></slot></div>`)
|
|
|
+ expect(fooVal).toBe('foo')
|
|
|
+ expect(barVal).toBe('bar')
|
|
|
+ })
|
|
|
})
|