feat(runtime-dom): support specifying shadow dom styles in defineCustomElement

This commit is contained in:
Evan You
2021-07-22 16:33:32 -04:00
parent f0ca233d8b
commit a7fa4ac28a
2 changed files with 29 additions and 6 deletions

View File

@@ -274,4 +274,20 @@ describe('defineCustomElement', () => {
expect(consumer.shadowRoot!.innerHTML).toBe(`<div>changed!</div>`)
})
})
describe('styles', () => {
test('should attach styles to shadow dom', () => {
const Foo = defineCustomElement({
styles: [`div { color: red; }`],
render() {
return h('div', 'hello')
}
})
customElements.define('my-el-with-styles', Foo)
container.innerHTML = `<my-el-with-styles></my-el-with-styles>`
const el = container.childNodes[0] as VueElement
const style = el.shadowRoot?.querySelector('style')!
expect(style.textContent).toBe(`div { color: red; }`)
})
})
})