wip(vitest-migration): compat tests passing

This commit is contained in:
Evan You 2023-01-26 20:24:54 +08:00
parent dca4224c2c
commit e478755c7d
11 changed files with 38 additions and 5 deletions

View File

@ -1,3 +1,6 @@
/**
* @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'

View File

@ -1,3 +1,6 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat' import Vue from '@vue/compat'
import { import {
DeprecationTypes, DeprecationTypes,

View File

@ -1,3 +1,6 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat' import Vue from '@vue/compat'
import { import {
DeprecationTypes, DeprecationTypes,
@ -52,7 +55,7 @@ describe('COMPONENT_FUNCTIONAL', () => {
expect(vm.$el.querySelector('.inject').textContent).toBe('123') expect(vm.$el.querySelector('.inject').textContent).toBe('123')
expect(vm.$el.querySelector('.slot').textContent).toBe('hello') expect(vm.$el.querySelector('.slot').textContent).toBe('hello')
expect(vm.$el.outerHTML).toMatchInlineSnapshot( expect(vm.$el.outerHTML).toMatchInlineSnapshot(
`"<div id="foo" class="foo"><div class="inject">123</div><div class="slot">hello</div></div>"` '"<div id=\\"foo\\" class=\\"foo\\"><div class=\\"inject\\">123</div><div class=\\"slot\\">hello</div></div>"'
) )
expect( expect(

View File

@ -1,3 +1,6 @@
/**
* @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'

View File

@ -1,3 +1,6 @@
/**
* @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 {

View File

@ -1,3 +1,6 @@
/**
* @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'

View File

@ -1,3 +1,6 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest' import { vi } from 'vitest'
import Vue from '@vue/compat' import Vue from '@vue/compat'
import { import {

View File

@ -1,4 +1,7 @@
import { vi } from 'vitest' /**
* @vitest-environment jsdom
*/
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'
import { Text } from '../../runtime-core/src/vnode' import { Text } from '../../runtime-core/src/vnode'
@ -50,7 +53,7 @@ test('INSTANCE_DESTROY', () => {
// https://github.com/vuejs/vue/blob/dev/test/unit/features/instance/methods-events.spec.js // https://github.com/vuejs/vue/blob/dev/test/unit/features/instance/methods-events.spec.js
describe('INSTANCE_EVENT_EMITTER', () => { describe('INSTANCE_EVENT_EMITTER', () => {
let vm: LegacyPublicInstance let vm: LegacyPublicInstance
let spy: vi.Mock let spy: Mock
beforeEach(() => { beforeEach(() => {
vm = new Vue() vm = new Vue()
@ -61,7 +64,7 @@ describe('INSTANCE_EVENT_EMITTER', () => {
vm.$on('test', function (this: any) { vm.$on('test', function (this: any) {
// expect correct context // expect correct context
expect(this).toBe(vm) expect(this).toBe(vm)
spy.apply(this, arguments) spy.apply(this, arguments as unknown as any[])
}) })
vm.$emit('test', 1, 2, 3, 4) vm.$emit('test', 1, 2, 3, 4)
expect(spy).toHaveBeenCalledTimes(1) expect(spy).toHaveBeenCalledTimes(1)
@ -74,7 +77,7 @@ describe('INSTANCE_EVENT_EMITTER', () => {
it('$on multi event', () => { it('$on multi event', () => {
vm.$on(['test1', 'test2'], function (this: any) { vm.$on(['test1', 'test2'], function (this: any) {
expect(this).toBe(vm) expect(this).toBe(vm)
spy.apply(this, arguments) spy.apply(this, arguments as unknown as any[])
}) })
vm.$emit('test1', 1, 2, 3, 4) vm.$emit('test1', 1, 2, 3, 4)
expect(spy).toHaveBeenCalledTimes(1) expect(spy).toHaveBeenCalledTimes(1)

View File

@ -1,3 +1,6 @@
/**
* @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'

View File

@ -1,3 +1,6 @@
/**
* @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'

View File

@ -1,3 +1,6 @@
/**
* @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'