customElement.spec.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. import { vi } from 'vitest'
  2. import {
  3. defineAsyncComponent,
  4. defineComponent,
  5. defineCustomElement,
  6. h,
  7. inject,
  8. nextTick,
  9. Ref,
  10. ref,
  11. renderSlot,
  12. VueElement
  13. } from '../src'
  14. describe('defineCustomElement', () => {
  15. const container = document.createElement('div')
  16. document.body.appendChild(container)
  17. beforeEach(() => {
  18. container.innerHTML = ''
  19. })
  20. describe('mounting/unmount', () => {
  21. const E = defineCustomElement({
  22. props: {
  23. msg: {
  24. type: String,
  25. default: 'hello'
  26. }
  27. },
  28. render() {
  29. return h('div', this.msg)
  30. }
  31. })
  32. customElements.define('my-element', E)
  33. test('should work', () => {
  34. container.innerHTML = `<my-element></my-element>`
  35. const e = container.childNodes[0] as VueElement
  36. expect(e).toBeInstanceOf(E)
  37. expect(e._instance).toBeTruthy()
  38. expect(e.shadowRoot!.innerHTML).toBe(`<div>hello</div>`)
  39. })
  40. test('should work w/ manual instantiation', () => {
  41. const e = new E({ msg: 'inline' })
  42. // should lazy init
  43. expect(e._instance).toBe(null)
  44. // should initialize on connect
  45. container.appendChild(e)
  46. expect(e._instance).toBeTruthy()
  47. expect(e.shadowRoot!.innerHTML).toBe(`<div>inline</div>`)
  48. })
  49. test('should unmount on remove', async () => {
  50. container.innerHTML = `<my-element></my-element>`
  51. const e = container.childNodes[0] as VueElement
  52. container.removeChild(e)
  53. await nextTick()
  54. expect(e._instance).toBe(null)
  55. expect(e.shadowRoot!.innerHTML).toBe('')
  56. })
  57. test('should not unmount on move', async () => {
  58. container.innerHTML = `<div><my-element></my-element></div>`
  59. const e = container.childNodes[0].childNodes[0] as VueElement
  60. const i = e._instance
  61. // moving from one parent to another - this will trigger both disconnect
  62. // and connected callbacks synchronously
  63. container.appendChild(e)
  64. await nextTick()
  65. // should be the same instance
  66. expect(e._instance).toBe(i)
  67. expect(e.shadowRoot!.innerHTML).toBe('<div>hello</div>')
  68. })
  69. test('remove then insert again', async () => {
  70. container.innerHTML = `<my-element></my-element>`
  71. const e = container.childNodes[0] as VueElement
  72. container.removeChild(e)
  73. await nextTick()
  74. expect(e._instance).toBe(null)
  75. expect(e.shadowRoot!.innerHTML).toBe('')
  76. container.appendChild(e)
  77. expect(e._instance).toBeTruthy()
  78. expect(e.shadowRoot!.innerHTML).toBe('<div>hello</div>')
  79. })
  80. })
  81. describe('props', () => {
  82. const E = defineCustomElement({
  83. props: ['foo', 'bar', 'bazQux'],
  84. render() {
  85. return [
  86. h('div', null, this.foo),
  87. h('div', null, this.bazQux || (this.bar && this.bar.x))
  88. ]
  89. }
  90. })
  91. customElements.define('my-el-props', E)
  92. test('props via attribute', async () => {
  93. // bazQux should map to `baz-qux` attribute
  94. container.innerHTML = `<my-el-props foo="hello" baz-qux="bye"></my-el-props>`
  95. const e = container.childNodes[0] as VueElement
  96. expect(e.shadowRoot!.innerHTML).toBe('<div>hello</div><div>bye</div>')
  97. // change attr
  98. e.setAttribute('foo', 'changed')
  99. await nextTick()
  100. expect(e.shadowRoot!.innerHTML).toBe('<div>changed</div><div>bye</div>')
  101. e.setAttribute('baz-qux', 'changed')
  102. await nextTick()
  103. expect(e.shadowRoot!.innerHTML).toBe(
  104. '<div>changed</div><div>changed</div>'
  105. )
  106. })
  107. test('props via properties', async () => {
  108. const e = new E()
  109. e.foo = 'one'
  110. e.bar = { x: 'two' }
  111. container.appendChild(e)
  112. expect(e.shadowRoot!.innerHTML).toBe('<div>one</div><div>two</div>')
  113. // reflect
  114. // should reflect primitive value
  115. expect(e.getAttribute('foo')).toBe('one')
  116. // should not reflect rich data
  117. expect(e.hasAttribute('bar')).toBe(false)
  118. e.foo = 'three'
  119. await nextTick()
  120. expect(e.shadowRoot!.innerHTML).toBe('<div>three</div><div>two</div>')
  121. expect(e.getAttribute('foo')).toBe('three')
  122. e.foo = null
  123. await nextTick()
  124. expect(e.shadowRoot!.innerHTML).toBe('<div></div><div>two</div>')
  125. expect(e.hasAttribute('foo')).toBe(false)
  126. e.bazQux = 'four'
  127. await nextTick()
  128. expect(e.shadowRoot!.innerHTML).toBe('<div></div><div>four</div>')
  129. expect(e.getAttribute('baz-qux')).toBe('four')
  130. })
  131. test('attribute -> prop type casting', async () => {
  132. const E = defineCustomElement({
  133. props: {
  134. fooBar: Number, // test casting of camelCase prop names
  135. bar: Boolean,
  136. baz: String
  137. },
  138. render() {
  139. return [
  140. this.fooBar,
  141. typeof this.fooBar,
  142. this.bar,
  143. typeof this.bar,
  144. this.baz,
  145. typeof this.baz
  146. ].join(' ')
  147. }
  148. })
  149. customElements.define('my-el-props-cast', E)
  150. container.innerHTML = `<my-el-props-cast foo-bar="1" baz="12345"></my-el-props-cast>`
  151. const e = container.childNodes[0] as VueElement
  152. expect(e.shadowRoot!.innerHTML).toBe(
  153. `1 number false boolean 12345 string`
  154. )
  155. e.setAttribute('bar', '')
  156. await nextTick()
  157. expect(e.shadowRoot!.innerHTML).toBe(`1 number true boolean 12345 string`)
  158. e.setAttribute('foo-bar', '2e1')
  159. await nextTick()
  160. expect(e.shadowRoot!.innerHTML).toBe(
  161. `20 number true boolean 12345 string`
  162. )
  163. e.setAttribute('baz', '2e1')
  164. await nextTick()
  165. expect(e.shadowRoot!.innerHTML).toBe(`20 number true boolean 2e1 string`)
  166. })
  167. // #4772
  168. test('attr casting w/ programmatic creation', () => {
  169. const E = defineCustomElement({
  170. props: {
  171. foo: Number
  172. },
  173. render() {
  174. return `foo type: ${typeof this.foo}`
  175. }
  176. })
  177. customElements.define('my-element-programmatic', E)
  178. const el = document.createElement('my-element-programmatic') as any
  179. el.setAttribute('foo', '123')
  180. container.appendChild(el)
  181. expect(el.shadowRoot.innerHTML).toBe(`foo type: number`)
  182. })
  183. test('handling properties set before upgrading', () => {
  184. const E = defineCustomElement({
  185. props: {
  186. foo: String,
  187. dataAge: Number
  188. },
  189. setup(props) {
  190. expect(props.foo).toBe('hello')
  191. expect(props.dataAge).toBe(5)
  192. },
  193. render() {
  194. return h('div', `foo: ${this.foo}`)
  195. }
  196. })
  197. const el = document.createElement('my-el-upgrade') as any
  198. el.foo = 'hello'
  199. el.dataset.age = 5
  200. el.notProp = 1
  201. container.appendChild(el)
  202. customElements.define('my-el-upgrade', E)
  203. expect(el.shadowRoot.firstChild.innerHTML).toBe(`foo: hello`)
  204. // should not reflect if not declared as a prop
  205. expect(el.hasAttribute('not-prop')).toBe(false)
  206. })
  207. test('handle properties set before connecting', () => {
  208. const obj = { a: 1 }
  209. const E = defineCustomElement({
  210. props: {
  211. foo: String,
  212. post: Object
  213. },
  214. setup(props) {
  215. expect(props.foo).toBe('hello')
  216. expect(props.post).toBe(obj)
  217. },
  218. render() {
  219. return JSON.stringify(this.post)
  220. }
  221. })
  222. customElements.define('my-el-preconnect', E)
  223. const el = document.createElement('my-el-preconnect') as any
  224. el.foo = 'hello'
  225. el.post = obj
  226. container.appendChild(el)
  227. expect(el.shadowRoot.innerHTML).toBe(JSON.stringify(obj))
  228. })
  229. // https://github.com/vuejs/core/issues/6163
  230. test('handle components with no props', async () => {
  231. const E = defineCustomElement({
  232. render() {
  233. return h('div', 'foo')
  234. }
  235. })
  236. customElements.define('my-element-noprops', E)
  237. const el = document.createElement('my-element-noprops')
  238. container.appendChild(el)
  239. await nextTick()
  240. expect(el.shadowRoot!.innerHTML).toMatchInlineSnapshot('"<div>foo</div>"')
  241. })
  242. // # 5793
  243. test('set number value in dom property', () => {
  244. const E = defineCustomElement({
  245. props: {
  246. 'max-age': Number
  247. },
  248. render() {
  249. // @ts-ignore
  250. return `max age: ${this.maxAge}/type: ${typeof this.maxAge}`
  251. }
  252. })
  253. customElements.define('my-element-number-property', E)
  254. const el = document.createElement('my-element-number-property') as any
  255. container.appendChild(el)
  256. el.maxAge = 50
  257. expect(el.maxAge).toBe(50)
  258. expect(el.shadowRoot.innerHTML).toBe('max age: 50/type: number')
  259. })
  260. })
  261. describe('attrs', () => {
  262. const E = defineCustomElement({
  263. render() {
  264. return [h('div', null, this.$attrs.foo as string)]
  265. }
  266. })
  267. customElements.define('my-el-attrs', E)
  268. test('attrs via attribute', async () => {
  269. container.innerHTML = `<my-el-attrs foo="hello"></my-el-attrs>`
  270. const e = container.childNodes[0] as VueElement
  271. expect(e.shadowRoot!.innerHTML).toBe('<div>hello</div>')
  272. e.setAttribute('foo', 'changed')
  273. await nextTick()
  274. expect(e.shadowRoot!.innerHTML).toBe('<div>changed</div>')
  275. })
  276. test('non-declared properties should not show up in $attrs', () => {
  277. const e = new E()
  278. // @ts-ignore
  279. e.foo = '123'
  280. container.appendChild(e)
  281. expect(e.shadowRoot!.innerHTML).toBe('<div></div>')
  282. })
  283. })
  284. describe('emits', () => {
  285. const CompDef = defineComponent({
  286. setup(_, { emit }) {
  287. emit('created')
  288. return () =>
  289. h('div', {
  290. onClick: () => {
  291. emit('my-click', 1)
  292. },
  293. onMousedown: () => {
  294. emit('myEvent', 1) // validate hypenization
  295. }
  296. })
  297. }
  298. })
  299. const E = defineCustomElement(CompDef)
  300. customElements.define('my-el-emits', E)
  301. test('emit on connect', () => {
  302. const e = new E()
  303. const spy = vi.fn()
  304. e.addEventListener('created', spy)
  305. container.appendChild(e)
  306. expect(spy).toHaveBeenCalled()
  307. })
  308. test('emit on interaction', () => {
  309. container.innerHTML = `<my-el-emits></my-el-emits>`
  310. const e = container.childNodes[0] as VueElement
  311. const spy = vi.fn()
  312. e.addEventListener('my-click', spy)
  313. e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
  314. expect(spy).toHaveBeenCalledTimes(1)
  315. expect(spy.mock.calls[0][0]).toMatchObject({
  316. detail: [1]
  317. })
  318. })
  319. // #5373
  320. test('case transform for camelCase event', () => {
  321. container.innerHTML = `<my-el-emits></my-el-emits>`
  322. const e = container.childNodes[0] as VueElement
  323. const spy1 = vi.fn()
  324. e.addEventListener('myEvent', spy1)
  325. const spy2 = vi.fn()
  326. // emitting myEvent, but listening for my-event. This happens when
  327. // using the custom element in a Vue template
  328. e.addEventListener('my-event', spy2)
  329. e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('mousedown'))
  330. expect(spy1).toHaveBeenCalledTimes(1)
  331. expect(spy2).toHaveBeenCalledTimes(1)
  332. })
  333. test('emit from within async component wrapper', async () => {
  334. const p = new Promise<typeof CompDef>(res => res(CompDef as any))
  335. const E = defineCustomElement(defineAsyncComponent(() => p))
  336. customElements.define('my-async-el-emits', E)
  337. container.innerHTML = `<my-async-el-emits></my-async-el-emits>`
  338. const e = container.childNodes[0] as VueElement
  339. const spy = vi.fn()
  340. e.addEventListener('my-click', spy)
  341. // this feels brittle but seems necessary to reach the node in the DOM.
  342. await customElements.whenDefined('my-async-el-emits')
  343. await nextTick()
  344. await nextTick()
  345. e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
  346. expect(spy).toHaveBeenCalled()
  347. expect(spy.mock.calls[0][0]).toMatchObject({
  348. detail: [1]
  349. })
  350. })
  351. // #7293
  352. test('emit in an async component wrapper with properties bound', async () => {
  353. const E = defineCustomElement(
  354. defineAsyncComponent(
  355. () => new Promise<typeof CompDef>(res => res(CompDef as any))
  356. )
  357. )
  358. customElements.define('my-async-el-props-emits', E)
  359. container.innerHTML = `<my-async-el-props-emits id="my_async_el_props_emits"></my-async-el-props-emits>`
  360. const e = container.childNodes[0] as VueElement
  361. const spy = vi.fn()
  362. e.addEventListener('my-click', spy)
  363. await customElements.whenDefined('my-async-el-props-emits')
  364. await nextTick()
  365. await nextTick()
  366. e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
  367. expect(spy).toHaveBeenCalled()
  368. expect(spy.mock.calls[0][0]).toMatchObject({
  369. detail: [1]
  370. })
  371. })
  372. })
  373. describe('slots', () => {
  374. const E = defineCustomElement({
  375. render() {
  376. return [
  377. h('div', null, [
  378. renderSlot(this.$slots, 'default', undefined, () => [
  379. h('div', 'fallback')
  380. ])
  381. ]),
  382. h('div', null, renderSlot(this.$slots, 'named'))
  383. ]
  384. }
  385. })
  386. customElements.define('my-el-slots', E)
  387. test('default slot', () => {
  388. container.innerHTML = `<my-el-slots><span>hi</span></my-el-slots>`
  389. const e = container.childNodes[0] as VueElement
  390. // native slots allocation does not affect innerHTML, so we just
  391. // verify that we've rendered the correct native slots here...
  392. expect(e.shadowRoot!.innerHTML).toBe(
  393. `<div><slot><div>fallback</div></slot></div><div><slot name="named"></slot></div>`
  394. )
  395. })
  396. })
  397. describe('provide/inject', () => {
  398. const Consumer = defineCustomElement({
  399. setup() {
  400. const foo = inject<Ref>('foo')!
  401. return () => h('div', foo.value)
  402. }
  403. })
  404. customElements.define('my-consumer', Consumer)
  405. test('over nested usage', async () => {
  406. const foo = ref('injected!')
  407. const Provider = defineCustomElement({
  408. provide: {
  409. foo
  410. },
  411. render() {
  412. return h('my-consumer')
  413. }
  414. })
  415. customElements.define('my-provider', Provider)
  416. container.innerHTML = `<my-provider><my-provider>`
  417. const provider = container.childNodes[0] as VueElement
  418. const consumer = provider.shadowRoot!.childNodes[0] as VueElement
  419. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>injected!</div>`)
  420. foo.value = 'changed!'
  421. await nextTick()
  422. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>changed!</div>`)
  423. })
  424. test('over slot composition', async () => {
  425. const foo = ref('injected!')
  426. const Provider = defineCustomElement({
  427. provide: {
  428. foo
  429. },
  430. render() {
  431. return renderSlot(this.$slots, 'default')
  432. }
  433. })
  434. customElements.define('my-provider-2', Provider)
  435. container.innerHTML = `<my-provider-2><my-consumer></my-consumer><my-provider-2>`
  436. const provider = container.childNodes[0]
  437. const consumer = provider.childNodes[0] as VueElement
  438. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>injected!</div>`)
  439. foo.value = 'changed!'
  440. await nextTick()
  441. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>changed!</div>`)
  442. })
  443. test('inherited from ancestors', async () => {
  444. const fooA = ref('FooA!')
  445. const fooB = ref('FooB!')
  446. const ProviderA = defineCustomElement({
  447. provide: {
  448. fooA
  449. },
  450. render() {
  451. return h('provider-b')
  452. }
  453. })
  454. const ProviderB = defineCustomElement({
  455. provide: {
  456. fooB
  457. },
  458. render() {
  459. return h('my-multi-consumer')
  460. }
  461. })
  462. const Consumer = defineCustomElement({
  463. setup() {
  464. const fooA = inject<Ref>('fooA')!
  465. const fooB = inject<Ref>('fooB')!
  466. return () => h('div', `${fooA.value} ${fooB.value}`)
  467. }
  468. })
  469. customElements.define('provider-a', ProviderA)
  470. customElements.define('provider-b', ProviderB)
  471. customElements.define('my-multi-consumer', Consumer)
  472. container.innerHTML = `<provider-a><provider-a>`
  473. const providerA = container.childNodes[0] as VueElement
  474. const providerB = providerA.shadowRoot!.childNodes[0] as VueElement
  475. const consumer = providerB.shadowRoot!.childNodes[0] as VueElement
  476. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>FooA! FooB!</div>`)
  477. fooA.value = 'changedA!'
  478. fooB.value = 'changedB!'
  479. await nextTick()
  480. expect(consumer.shadowRoot!.innerHTML).toBe(
  481. `<div>changedA! changedB!</div>`
  482. )
  483. })
  484. })
  485. describe('styles', () => {
  486. test('should attach styles to shadow dom', () => {
  487. const Foo = defineCustomElement({
  488. styles: [`div { color: red; }`],
  489. render() {
  490. return h('div', 'hello')
  491. }
  492. })
  493. customElements.define('my-el-with-styles', Foo)
  494. container.innerHTML = `<my-el-with-styles></my-el-with-styles>`
  495. const el = container.childNodes[0] as VueElement
  496. const style = el.shadowRoot?.querySelector('style')!
  497. expect(style.textContent).toBe(`div { color: red; }`)
  498. })
  499. })
  500. describe('async', () => {
  501. test('should work', async () => {
  502. const loaderSpy = vi.fn()
  503. const E = defineCustomElement(
  504. defineAsyncComponent(() => {
  505. loaderSpy()
  506. return Promise.resolve({
  507. props: ['msg'],
  508. styles: [`div { color: red }`],
  509. render(this: any) {
  510. return h('div', null, this.msg)
  511. }
  512. })
  513. })
  514. )
  515. customElements.define('my-el-async', E)
  516. container.innerHTML =
  517. `<my-el-async msg="hello"></my-el-async>` +
  518. `<my-el-async msg="world"></my-el-async>`
  519. await new Promise(r => setTimeout(r))
  520. // loader should be called only once
  521. expect(loaderSpy).toHaveBeenCalledTimes(1)
  522. const e1 = container.childNodes[0] as VueElement
  523. const e2 = container.childNodes[1] as VueElement
  524. // should inject styles
  525. expect(e1.shadowRoot!.innerHTML).toBe(
  526. `<style>div { color: red }</style><div>hello</div>`
  527. )
  528. expect(e2.shadowRoot!.innerHTML).toBe(
  529. `<style>div { color: red }</style><div>world</div>`
  530. )
  531. // attr
  532. e1.setAttribute('msg', 'attr')
  533. await nextTick()
  534. expect((e1 as any).msg).toBe('attr')
  535. expect(e1.shadowRoot!.innerHTML).toBe(
  536. `<style>div { color: red }</style><div>attr</div>`
  537. )
  538. // props
  539. expect(`msg` in e1).toBe(true)
  540. ;(e1 as any).msg = 'prop'
  541. expect(e1.getAttribute('msg')).toBe('prop')
  542. expect(e1.shadowRoot!.innerHTML).toBe(
  543. `<style>div { color: red }</style><div>prop</div>`
  544. )
  545. })
  546. test('set DOM property before resolve', async () => {
  547. const E = defineCustomElement(
  548. defineAsyncComponent(() => {
  549. return Promise.resolve({
  550. props: ['msg'],
  551. setup(props) {
  552. expect(typeof props.msg).toBe('string')
  553. },
  554. render(this: any) {
  555. return h('div', this.msg)
  556. }
  557. })
  558. })
  559. )
  560. customElements.define('my-el-async-2', E)
  561. const e1 = new E()
  562. // set property before connect
  563. e1.msg = 'hello'
  564. const e2 = new E()
  565. container.appendChild(e1)
  566. container.appendChild(e2)
  567. // set property after connect but before resolve
  568. e2.msg = 'world'
  569. await new Promise(r => setTimeout(r))
  570. expect(e1.shadowRoot!.innerHTML).toBe(`<div>hello</div>`)
  571. expect(e2.shadowRoot!.innerHTML).toBe(`<div>world</div>`)
  572. e1.msg = 'world'
  573. expect(e1.shadowRoot!.innerHTML).toBe(`<div>world</div>`)
  574. e2.msg = 'hello'
  575. expect(e2.shadowRoot!.innerHTML).toBe(`<div>hello</div>`)
  576. })
  577. test('Number prop casting before resolve', async () => {
  578. const E = defineCustomElement(
  579. defineAsyncComponent(() => {
  580. return Promise.resolve({
  581. props: { n: Number },
  582. setup(props) {
  583. expect(props.n).toBe(20)
  584. },
  585. render(this: any) {
  586. return h('div', this.n + ',' + typeof this.n)
  587. }
  588. })
  589. })
  590. )
  591. customElements.define('my-el-async-3', E)
  592. container.innerHTML = `<my-el-async-3 n="2e1"></my-el-async-3>`
  593. await new Promise(r => setTimeout(r))
  594. const e = container.childNodes[0] as VueElement
  595. expect(e.shadowRoot!.innerHTML).toBe(`<div>20,number</div>`)
  596. })
  597. test('with slots', async () => {
  598. const E = defineCustomElement(
  599. defineAsyncComponent(() => {
  600. return Promise.resolve({
  601. render(this: any) {
  602. return [
  603. h('div', null, [
  604. renderSlot(this.$slots, 'default', undefined, () => [
  605. h('div', 'fallback')
  606. ])
  607. ]),
  608. h('div', null, renderSlot(this.$slots, 'named'))
  609. ]
  610. }
  611. })
  612. })
  613. )
  614. customElements.define('my-el-async-slots', E)
  615. container.innerHTML = `<my-el-async-slots><span>hi</span></my-el-async-slots>`
  616. await new Promise(r => setTimeout(r))
  617. const e = container.childNodes[0] as VueElement
  618. expect(e.shadowRoot!.innerHTML).toBe(
  619. `<div><slot><div>fallback</div></slot></div><div><slot name="named"></slot></div>`
  620. )
  621. })
  622. })
  623. })