Skip to content

Commit

Permalink
wip(vitest-migration): runtime-dom tests passing + use environmentMat…
Browse files Browse the repository at this point in the history
…chGlobs
  • Loading branch information
yyx990803 committed Jan 26, 2023
1 parent a6be280 commit 4ee0dad
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 43 deletions.
11 changes: 6 additions & 5 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,17 @@ describe('defineCustomElement', () => {
})

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
const spy = vi.fn()
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({
Expand All @@ -398,6 +397,8 @@ describe('defineCustomElement', () => {
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({
Expand Down
7 changes: 3 additions & 4 deletions packages/runtime-dom/__tests__/patchEvents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,14 @@ describe(`runtime-dom: events patching`, () => {
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()
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/compiler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '@vue/runtime-core'
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/componentAsync.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat'
import {
DeprecationTypes,
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/componentFunctional.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat'
import {
DeprecationTypes,
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/componentVModel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat'
import { ComponentOptions } from '../../runtime-core/src/component'
import { nextTick } from '../../runtime-core/src/scheduler'
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/filters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat'
import { CompilerDeprecationTypes } from '../../compiler-core/src'
import {
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/global.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { effect, isReactive } from '@vue/reactivity'
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/globalConfig.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import {
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/instance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi, Mock } from 'vitest'
import Vue from '@vue/compat'
import { Slots } from '../../runtime-core/src/componentSlots'
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/misc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/options.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'
Expand Down
3 changes: 0 additions & 3 deletions packages/vue-compat/__tests__/renderFn.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { ShapeFlags } from '@vue/shared'
import Vue from '@vue/compat'
import { createComponentInstance } from '../../runtime-core/src/component'
Expand Down
3 changes: 2 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default defineConfig({
},
test: {
globals: true,
setupFiles: 'scripts/setupVitest.ts'
setupFiles: 'scripts/setupVitest.ts',
environmentMatchGlobs: [['packages/{vue-compat,runtime-dom}/**', 'jsdom']]
}
})

0 comments on commit 4ee0dad

Please sign in to comment.