customElement.spec.ts 21 KB

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