customElement.spec.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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 hypenization
  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 = jest.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 = jest.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 = jest.fn()
  323. e.addEventListener('myEvent', spy1)
  324. const spy2 = jest.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 E = defineCustomElement(
  334. defineAsyncComponent(
  335. () => new Promise<typeof CompDef>(res => res(CompDef as any))
  336. )
  337. )
  338. customElements.define('my-async-el-emits', E)
  339. container.innerHTML = `<my-async-el-emits></my-async-el-emits>`
  340. const e = container.childNodes[0] as VueElement
  341. const spy = jest.fn()
  342. e.addEventListener('my-click', spy)
  343. // this feels brittle but seems necessary to reach the node in the DOM.
  344. await customElements.whenDefined('my-async-el-emits')
  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 = jest.fn()
  362. e.addEventListener('my-click', spy)
  363. await customElements.whenDefined('my-async-el-props-emits')
  364. e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
  365. expect(spy).toHaveBeenCalled()
  366. expect(spy.mock.calls[0][0]).toMatchObject({
  367. detail: [1]
  368. })
  369. })
  370. })
  371. describe('slots', () => {
  372. const E = defineCustomElement({
  373. render() {
  374. return [
  375. h('div', null, [
  376. renderSlot(this.$slots, 'default', undefined, () => [
  377. h('div', 'fallback')
  378. ])
  379. ]),
  380. h('div', null, renderSlot(this.$slots, 'named'))
  381. ]
  382. }
  383. })
  384. customElements.define('my-el-slots', E)
  385. test('default slot', () => {
  386. container.innerHTML = `<my-el-slots><span>hi</span></my-el-slots>`
  387. const e = container.childNodes[0] as VueElement
  388. // native slots allocation does not affect innerHTML, so we just
  389. // verify that we've rendered the correct native slots here...
  390. expect(e.shadowRoot!.innerHTML).toBe(
  391. `<div><slot><div>fallback</div></slot></div><div><slot name="named"></slot></div>`
  392. )
  393. })
  394. })
  395. describe('provide/inject', () => {
  396. const Consumer = defineCustomElement({
  397. setup() {
  398. const foo = inject<Ref>('foo')!
  399. return () => h('div', foo.value)
  400. }
  401. })
  402. customElements.define('my-consumer', Consumer)
  403. test('over nested usage', async () => {
  404. const foo = ref('injected!')
  405. const Provider = defineCustomElement({
  406. provide: {
  407. foo
  408. },
  409. render() {
  410. return h('my-consumer')
  411. }
  412. })
  413. customElements.define('my-provider', Provider)
  414. container.innerHTML = `<my-provider><my-provider>`
  415. const provider = container.childNodes[0] as VueElement
  416. const consumer = provider.shadowRoot!.childNodes[0] as VueElement
  417. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>injected!</div>`)
  418. foo.value = 'changed!'
  419. await nextTick()
  420. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>changed!</div>`)
  421. })
  422. test('over slot composition', async () => {
  423. const foo = ref('injected!')
  424. const Provider = defineCustomElement({
  425. provide: {
  426. foo
  427. },
  428. render() {
  429. return renderSlot(this.$slots, 'default')
  430. }
  431. })
  432. customElements.define('my-provider-2', Provider)
  433. container.innerHTML = `<my-provider-2><my-consumer></my-consumer><my-provider-2>`
  434. const provider = container.childNodes[0]
  435. const consumer = provider.childNodes[0] as VueElement
  436. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>injected!</div>`)
  437. foo.value = 'changed!'
  438. await nextTick()
  439. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>changed!</div>`)
  440. })
  441. test('inherited from ancestors', async () => {
  442. const fooA = ref('FooA!')
  443. const fooB = ref('FooB!')
  444. const ProviderA = defineCustomElement({
  445. provide: {
  446. fooA
  447. },
  448. render() {
  449. return h('provider-b')
  450. }
  451. })
  452. const ProviderB = defineCustomElement({
  453. provide: {
  454. fooB
  455. },
  456. render() {
  457. return h('my-multi-consumer')
  458. }
  459. })
  460. const Consumer = defineCustomElement({
  461. setup() {
  462. const fooA = inject<Ref>('fooA')!
  463. const fooB = inject<Ref>('fooB')!
  464. return () => h('div', `${fooA.value} ${fooB.value}`)
  465. }
  466. })
  467. customElements.define('provider-a', ProviderA)
  468. customElements.define('provider-b', ProviderB)
  469. customElements.define('my-multi-consumer', Consumer)
  470. container.innerHTML = `<provider-a><provider-a>`
  471. const providerA = container.childNodes[0] as VueElement
  472. const providerB = providerA.shadowRoot!.childNodes[0] as VueElement
  473. const consumer = providerB.shadowRoot!.childNodes[0] as VueElement
  474. expect(consumer.shadowRoot!.innerHTML).toBe(`<div>FooA! FooB!</div>`)
  475. fooA.value = 'changedA!'
  476. fooB.value = 'changedB!'
  477. await nextTick()
  478. expect(consumer.shadowRoot!.innerHTML).toBe(
  479. `<div>changedA! changedB!</div>`
  480. )
  481. })
  482. })
  483. describe('styles', () => {
  484. test('should attach styles to shadow dom', () => {
  485. const Foo = defineCustomElement({
  486. styles: [`div { color: red; }`],
  487. render() {
  488. return h('div', 'hello')
  489. }
  490. })
  491. customElements.define('my-el-with-styles', Foo)
  492. container.innerHTML = `<my-el-with-styles></my-el-with-styles>`
  493. const el = container.childNodes[0] as VueElement
  494. const style = el.shadowRoot?.querySelector('style')!
  495. expect(style.textContent).toBe(`div { color: red; }`)
  496. })
  497. })
  498. describe('async', () => {
  499. test('should work', async () => {
  500. const loaderSpy = jest.fn()
  501. const E = defineCustomElement(
  502. defineAsyncComponent(() => {
  503. loaderSpy()
  504. return Promise.resolve({
  505. props: ['msg'],
  506. styles: [`div { color: red }`],
  507. render(this: any) {
  508. return h('div', null, this.msg)
  509. }
  510. })
  511. })
  512. )
  513. customElements.define('my-el-async', E)
  514. container.innerHTML =
  515. `<my-el-async msg="hello"></my-el-async>` +
  516. `<my-el-async msg="world"></my-el-async>`
  517. await new Promise(r => setTimeout(r))
  518. // loader should be called only once
  519. expect(loaderSpy).toHaveBeenCalledTimes(1)
  520. const e1 = container.childNodes[0] as VueElement
  521. const e2 = container.childNodes[1] as VueElement
  522. // should inject styles
  523. expect(e1.shadowRoot!.innerHTML).toBe(
  524. `<style>div { color: red }</style><div>hello</div>`
  525. )
  526. expect(e2.shadowRoot!.innerHTML).toBe(
  527. `<style>div { color: red }</style><div>world</div>`
  528. )
  529. // attr
  530. e1.setAttribute('msg', 'attr')
  531. await nextTick()
  532. expect((e1 as any).msg).toBe('attr')
  533. expect(e1.shadowRoot!.innerHTML).toBe(
  534. `<style>div { color: red }</style><div>attr</div>`
  535. )
  536. // props
  537. expect(`msg` in e1).toBe(true)
  538. ;(e1 as any).msg = 'prop'
  539. expect(e1.getAttribute('msg')).toBe('prop')
  540. expect(e1.shadowRoot!.innerHTML).toBe(
  541. `<style>div { color: red }</style><div>prop</div>`
  542. )
  543. })
  544. test('set DOM property before resolve', async () => {
  545. const E = defineCustomElement(
  546. defineAsyncComponent(() => {
  547. return Promise.resolve({
  548. props: ['msg'],
  549. setup(props) {
  550. expect(typeof props.msg).toBe('string')
  551. },
  552. render(this: any) {
  553. return h('div', this.msg)
  554. }
  555. })
  556. })
  557. )
  558. customElements.define('my-el-async-2', E)
  559. const e1 = new E()
  560. // set property before connect
  561. e1.msg = 'hello'
  562. const e2 = new E()
  563. container.appendChild(e1)
  564. container.appendChild(e2)
  565. // set property after connect but before resolve
  566. e2.msg = 'world'
  567. await new Promise(r => setTimeout(r))
  568. expect(e1.shadowRoot!.innerHTML).toBe(`<div>hello</div>`)
  569. expect(e2.shadowRoot!.innerHTML).toBe(`<div>world</div>`)
  570. e1.msg = 'world'
  571. expect(e1.shadowRoot!.innerHTML).toBe(`<div>world</div>`)
  572. e2.msg = 'hello'
  573. expect(e2.shadowRoot!.innerHTML).toBe(`<div>hello</div>`)
  574. })
  575. test('Number prop casting before resolve', async () => {
  576. const E = defineCustomElement(
  577. defineAsyncComponent(() => {
  578. return Promise.resolve({
  579. props: { n: Number },
  580. setup(props) {
  581. expect(props.n).toBe(20)
  582. },
  583. render(this: any) {
  584. return h('div', this.n + ',' + typeof this.n)
  585. }
  586. })
  587. })
  588. )
  589. customElements.define('my-el-async-3', E)
  590. container.innerHTML = `<my-el-async-3 n="2e1"></my-el-async-3>`
  591. await new Promise(r => setTimeout(r))
  592. const e = container.childNodes[0] as VueElement
  593. expect(e.shadowRoot!.innerHTML).toBe(`<div>20,number</div>`)
  594. })
  595. test('with slots', async () => {
  596. const E = defineCustomElement(
  597. defineAsyncComponent(() => {
  598. return Promise.resolve({
  599. render(this: any) {
  600. return [
  601. h('div', null, [
  602. renderSlot(this.$slots, 'default', undefined, () => [
  603. h('div', 'fallback')
  604. ])
  605. ]),
  606. h('div', null, renderSlot(this.$slots, 'named'))
  607. ]
  608. }
  609. })
  610. })
  611. )
  612. customElements.define('my-el-async-slots', E)
  613. container.innerHTML = `<my-el-async-slots><span>hi</span></my-el-async-slots>`
  614. await new Promise(r => setTimeout(r))
  615. const e = container.childNodes[0] as VueElement
  616. expect(e.shadowRoot!.innerHTML).toBe(
  617. `<div><slot><div>fallback</div></slot></div><div><slot name="named"></slot></div>`
  618. )
  619. })
  620. })
  621. })