mirror of https://github.com/vuejs/core.git
wip(vitest-migration): runtime-dom tests passing + use environmentMatchGlobs
This commit is contained in:
parent
a6be280fc3
commit
4ee0dad0fe
|
@ -367,11 +367,8 @@ describe('defineCustomElement', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('emit from within async component wrapper', async () => {
|
test('emit from within async component wrapper', async () => {
|
||||||
const E = defineCustomElement(
|
const p = new Promise<typeof CompDef>(res => res(CompDef as any))
|
||||||
defineAsyncComponent(
|
const E = defineCustomElement(defineAsyncComponent(() => p))
|
||||||
() => new Promise<typeof CompDef>(res => res(CompDef as any))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
customElements.define('my-async-el-emits', E)
|
customElements.define('my-async-el-emits', E)
|
||||||
container.innerHTML = `<my-async-el-emits></my-async-el-emits>`
|
container.innerHTML = `<my-async-el-emits></my-async-el-emits>`
|
||||||
const e = container.childNodes[0] as VueElement
|
const e = container.childNodes[0] as VueElement
|
||||||
|
@ -379,6 +376,8 @@ describe('defineCustomElement', () => {
|
||||||
e.addEventListener('my-click', spy)
|
e.addEventListener('my-click', spy)
|
||||||
// this feels brittle but seems necessary to reach the node in the DOM.
|
// this feels brittle but seems necessary to reach the node in the DOM.
|
||||||
await customElements.whenDefined('my-async-el-emits')
|
await customElements.whenDefined('my-async-el-emits')
|
||||||
|
await nextTick()
|
||||||
|
await nextTick()
|
||||||
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
|
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
|
||||||
expect(spy).toHaveBeenCalled()
|
expect(spy).toHaveBeenCalled()
|
||||||
expect(spy.mock.calls[0][0]).toMatchObject({
|
expect(spy.mock.calls[0][0]).toMatchObject({
|
||||||
|
@ -398,6 +397,8 @@ describe('defineCustomElement', () => {
|
||||||
const spy = vi.fn()
|
const spy = vi.fn()
|
||||||
e.addEventListener('my-click', spy)
|
e.addEventListener('my-click', spy)
|
||||||
await customElements.whenDefined('my-async-el-props-emits')
|
await customElements.whenDefined('my-async-el-props-emits')
|
||||||
|
await nextTick()
|
||||||
|
await nextTick()
|
||||||
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
|
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
|
||||||
expect(spy).toHaveBeenCalled()
|
expect(spy).toHaveBeenCalled()
|
||||||
expect(spy.mock.calls[0][0]).toMatchObject({
|
expect(spy.mock.calls[0][0]).toMatchObject({
|
||||||
|
|
|
@ -85,15 +85,14 @@ describe(`runtime-dom: events patching`, () => {
|
||||||
const el = document.createElement('div')
|
const el = document.createElement('div')
|
||||||
|
|
||||||
// string should be set as attribute
|
// string should be set as attribute
|
||||||
const fn = ((window as any).__globalSpy = vi.fn())
|
const fn = ((el as any).spy = vi.fn())
|
||||||
patchProp(el, 'onclick', null, '__globalSpy(1)')
|
patchProp(el, 'onclick', null, 'this.spy(1)')
|
||||||
el.dispatchEvent(new Event('click'))
|
el.dispatchEvent(new Event('click'))
|
||||||
await timeout()
|
await timeout()
|
||||||
delete (window as any).__globalSpy
|
|
||||||
expect(fn).toHaveBeenCalledWith(1)
|
expect(fn).toHaveBeenCalledWith(1)
|
||||||
|
|
||||||
const fn2 = vi.fn()
|
const fn2 = vi.fn()
|
||||||
patchProp(el, 'onclick', '__globalSpy(1)', fn2)
|
patchProp(el, 'onclick', 'this.spy(1)', fn2)
|
||||||
const event = new Event('click')
|
const event = new Event('click')
|
||||||
el.dispatchEvent(event)
|
el.dispatchEvent(event)
|
||||||
await timeout()
|
await timeout()
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import { vi } from 'vitest'
|
import { vi } from 'vitest'
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import { nextTick } from '@vue/runtime-core'
|
import { nextTick } from '@vue/runtime-core'
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import {
|
import {
|
||||||
DeprecationTypes,
|
DeprecationTypes,
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import {
|
import {
|
||||||
DeprecationTypes,
|
DeprecationTypes,
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import { ComponentOptions } from '../../runtime-core/src/component'
|
import { ComponentOptions } from '../../runtime-core/src/component'
|
||||||
import { nextTick } from '../../runtime-core/src/scheduler'
|
import { nextTick } from '../../runtime-core/src/scheduler'
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import { CompilerDeprecationTypes } from '../../compiler-core/src'
|
import { CompilerDeprecationTypes } from '../../compiler-core/src'
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import { vi } from 'vitest'
|
import { vi } from 'vitest'
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import { effect, isReactive } from '@vue/reactivity'
|
import { effect, isReactive } from '@vue/reactivity'
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import { vi } from 'vitest'
|
import { vi } from 'vitest'
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import { vi, Mock } from 'vitest'
|
import { vi, Mock } from 'vitest'
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import { Slots } from '../../runtime-core/src/componentSlots'
|
import { Slots } from '../../runtime-core/src/componentSlots'
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import { vi } from 'vitest'
|
import { vi } from 'vitest'
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import { nextTick } from '../../runtime-core/src/scheduler'
|
import { nextTick } from '../../runtime-core/src/scheduler'
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import { vi } from 'vitest'
|
import { vi } from 'vitest'
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import { nextTick } from '../../runtime-core/src/scheduler'
|
import { nextTick } from '../../runtime-core/src/scheduler'
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* @vitest-environment jsdom
|
|
||||||
*/
|
|
||||||
import { ShapeFlags } from '@vue/shared'
|
import { ShapeFlags } from '@vue/shared'
|
||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import { createComponentInstance } from '../../runtime-core/src/component'
|
import { createComponentInstance } from '../../runtime-core/src/component'
|
||||||
|
|
|
@ -42,6 +42,7 @@ export default defineConfig({
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
globals: true,
|
globals: true,
|
||||||
setupFiles: 'scripts/setupVitest.ts'
|
setupFiles: 'scripts/setupVitest.ts',
|
||||||
|
environmentMatchGlobs: [['packages/{vue-compat,runtime-dom}/**', 'jsdom']]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue