Skip to content

Commit 419b6cb

Browse files
authored
test(custom-element): add vapor test for slotted shadow DOM parent resolution (#14584)
sync from #12480
1 parent c4b51d8 commit 419b6cb

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,30 @@ describe('defineVaporCustomElement', () => {
931931
)
932932
})
933933

934+
test('should resolve correct parent when element is slotted in shadow DOM', async () => {
935+
const GrandParent = defineVaporCustomElement({
936+
setup() {
937+
provide('foo', ref('GrandParent'))
938+
const n0 = createPlainElement('my-parent-in-shadow', null, {
939+
default: () => template('<slot></slot>')(),
940+
})
941+
return n0
942+
},
943+
})
944+
const Parent = defineVaporCustomElement({
945+
setup() {
946+
provide('foo', ref('Parent'))
947+
return template('<slot></slot>')()
948+
},
949+
})
950+
customElements.define('my-grand-parent', GrandParent)
951+
customElements.define('my-parent-in-shadow', Parent)
952+
container.innerHTML = `<my-grand-parent><my-consumer></my-consumer></my-grand-parent>`
953+
const grandParent = container.childNodes[0] as VaporElement,
954+
consumer = grandParent.firstElementChild as VaporElement
955+
expect(consumer.shadowRoot!.textContent).toBe('Parent')
956+
})
957+
934958
test('inherited from app context within nested elements', async () => {
935959
const outerValues: (string | undefined)[] = []
936960
const innerValues: (string | undefined)[] = []

0 commit comments

Comments
 (0)