From f6eaa8879c34e65672bf4005fd412a69fe7c75d7 Mon Sep 17 00:00:00 2001 From: daiwei Date: Tue, 28 Oct 2025 16:02:07 +0800 Subject: [PATCH] wip: save --- .../__tests__/customElement.spec.ts | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/packages/runtime-vapor/__tests__/customElement.spec.ts b/packages/runtime-vapor/__tests__/customElement.spec.ts index 6072da34a2..754f2b8aec 100644 --- a/packages/runtime-vapor/__tests__/customElement.spec.ts +++ b/packages/runtime-vapor/__tests__/customElement.spec.ts @@ -1089,46 +1089,46 @@ describe('defineVaporCustomElement', () => { assertStyles(el, [`div { color: blue; }`, `div { color: red; }`]) }) - // test("child components should not inject styles to root element's shadow root w/ shadowRoot false", async () => { - // const Bar = defineVaporComponent({ - // styles: [`div { color: green; }`], - // render() { - // return 'bar' - // }, - // }) - // const Baz = () => h(Bar) - // const Foo = defineVaporCustomElement( - // { - // render() { - // return [h(Baz)] - // }, - // }, - // { shadowRoot: false }, - // ) + test("child components should not inject styles to root element's shadow root w/ shadowRoot false", async () => { + const Bar = defineVaporComponent({ + styles: [`div { color: green; }`], + setup() { + return template('bar')() + }, + } as any) + const Baz = () => createComponent(Bar) + const Foo = defineVaporCustomElement( + { + setup() { + return [createComponent(Baz)] + }, + }, + { shadowRoot: false } as any, + ) - // customElements.define('my-foo-with-shadowroot-false', Foo) - // container.innerHTML = `` - // const el = container.childNodes[0] as VaporElement - // const style = el.shadowRoot?.querySelector('style') - // expect(style).toBeUndefined() - // }) + customElements.define('my-foo-with-shadowroot-false', Foo) + container.innerHTML = `` + const el = container.childNodes[0] as VaporElement + const style = el.shadowRoot?.querySelector('style') + expect(style).toBeUndefined() + }) - // test('with nonce', () => { - // const Foo = defineVaporCustomElement( - // { - // styles: [`div { color: red; }`], - // render() { - // return h('div', 'hello') - // }, - // }, - // { nonce: 'xxx' }, - // ) - // customElements.define('my-el-with-nonce', Foo) - // container.innerHTML = `` - // const el = container.childNodes[0] as VaporElement - // const style = el.shadowRoot?.querySelector('style')! - // expect(style.getAttribute('nonce')).toBe('xxx') - // }) + test('with nonce', () => { + const Foo = defineVaporCustomElement( + { + styles: [`div { color: red; }`], + setup() { + return template('
hello
', true)() + }, + }, + { nonce: 'xxx' } as any, + ) + customElements.define('my-el-with-nonce', Foo) + container.innerHTML = `` + const el = container.childNodes[0] as VaporElement + const style = el.shadowRoot?.querySelector('style')! + expect(style.getAttribute('nonce')).toBe('xxx') + }) }) // describe('async', () => { -- 2.47.3