})
test('emit from within async component wrapper', async () => {
- const E = defineCustomElement(
- defineAsyncComponent(
- () => new Promise<typeof CompDef>(res => res(CompDef as any))
- )
- )
+ const p = new Promise<typeof CompDef>(res => res(CompDef as any))
+ const E = defineCustomElement(defineAsyncComponent(() => p))
customElements.define('my-async-el-emits', E)
container.innerHTML = `<my-async-el-emits></my-async-el-emits>`
const e = container.childNodes[0] as VueElement
e.addEventListener('my-click', spy)
// this feels brittle but seems necessary to reach the node in the DOM.
await customElements.whenDefined('my-async-el-emits')
+ await nextTick()
+ await nextTick()
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
expect(spy).toHaveBeenCalled()
expect(spy.mock.calls[0][0]).toMatchObject({
const spy = vi.fn()
e.addEventListener('my-click', spy)
await customElements.whenDefined('my-async-el-props-emits')
+ await nextTick()
+ await nextTick()
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
expect(spy).toHaveBeenCalled()
expect(spy.mock.calls[0][0]).toMatchObject({
const el = document.createElement('div')
// string should be set as attribute
- const fn = ((window as any).__globalSpy = vi.fn())
- patchProp(el, 'onclick', null, '__globalSpy(1)')
+ const fn = ((el as any).spy = vi.fn())
+ patchProp(el, 'onclick', null, 'this.spy(1)')
el.dispatchEvent(new Event('click'))
await timeout()
- delete (window as any).__globalSpy
expect(fn).toHaveBeenCalledWith(1)
const fn2 = vi.fn()
- patchProp(el, 'onclick', '__globalSpy(1)', fn2)
+ patchProp(el, 'onclick', 'this.spy(1)', fn2)
const event = new Event('click')
el.dispatchEvent(event)
await timeout()
-/**
- * @vitest-environment jsdom
- */
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '@vue/runtime-core'
-/**
- * @vitest-environment jsdom
- */
import Vue from '@vue/compat'
import {
DeprecationTypes,
-/**
- * @vitest-environment jsdom
- */
import Vue from '@vue/compat'
import {
DeprecationTypes,
-/**
- * @vitest-environment jsdom
- */
import Vue from '@vue/compat'
import { ComponentOptions } from '../../runtime-core/src/component'
import { nextTick } from '../../runtime-core/src/scheduler'
-/**
- * @vitest-environment jsdom
- */
import Vue from '@vue/compat'
import { CompilerDeprecationTypes } from '../../compiler-core/src'
import {
-/**
- * @vitest-environment jsdom
- */
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { effect, isReactive } from '@vue/reactivity'
-/**
- * @vitest-environment jsdom
- */
import { vi } from 'vitest'
import Vue from '@vue/compat'
import {
-/**
- * @vitest-environment jsdom
- */
import { vi, Mock } from 'vitest'
import Vue from '@vue/compat'
import { Slots } from '../../runtime-core/src/componentSlots'
-/**
- * @vitest-environment jsdom
- */
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'
-/**
- * @vitest-environment jsdom
- */
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'
-/**
- * @vitest-environment jsdom
- */
import { ShapeFlags } from '@vue/shared'
import Vue from '@vue/compat'
import { createComponentInstance } from '../../runtime-core/src/component'
},
test: {
globals: true,
- setupFiles: 'scripts/setupVitest.ts'
+ setupFiles: 'scripts/setupVitest.ts',
+ environmentMatchGlobs: [['packages/{vue-compat,runtime-dom}/**', 'jsdom']]
}
})