"tslib": "^2.4.0",
"typescript": "^4.8.0",
"vite": "^4.0.4",
+ "vitest": "^0.28.2",
"vue": "workspace:*"
}
}
+import { vi } from 'vitest'
import { ParserOptions } from '../src/options'
import { baseParse, TextModes } from '../src/parse'
import { ErrorCodes } from '../src/errors'
})
test('simple text with invalid end tag', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const ast = baseParse('some text</div>', {
onError
})
baseParse(`<div>\n<span>\n</div>\n</span>`)
}).toThrow('Element is missing end tag.')
- const spy = jest.fn()
+ const spy = vi.fn()
const ast = baseParse(`<div>\n<span>\n</div>\n</span>`, {
onError: spy
})
c => `\\x0${c.codePointAt(0)!.toString(16)};`
),
() => {
- const spy = jest.fn()
+ const spy = vi.fn()
const ast = baseParse(code, {
getNamespace: (tag, parent) => {
const ns = parent ? parent.ns : Namespaces.HTML
+import { vi } from 'vitest'
import { baseParse } from '../src/parse'
import { transform, NodeTransform } from '../src/transform'
import {
)
}
}
- const spy = jest.fn(plugin)
+ const spy = vi.fn(plugin)
transform(ast, {
nodeTransforms: [spy]
})
context.removeNode()
}
}
- const spy = jest.fn(plugin)
+ const spy = vi.fn(plugin)
transform(ast, {
nodeTransforms: [spy]
})
context.removeNode(context.parent!.children[0])
}
}
- const spy = jest.fn(plugin)
+ const spy = vi.fn(plugin)
transform(ast, {
nodeTransforms: [spy]
})
context.removeNode(context.parent!.children[1])
}
}
- const spy = jest.fn(plugin)
+ const spy = vi.fn(plugin)
transform(ast, {
nodeTransforms: [spy]
})
createCompilerError(ErrorCodes.X_INVALID_END_TAG, node.loc)
)
}
- const spy = jest.fn()
+ const spy = vi.fn()
transform(ast, {
nodeTransforms: [plugin],
onError: spy
+import { vi } from 'vitest'
import {
CompilerOptions,
baseParse as parse,
})
test('error on v-bind with no argument', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithElementTransform(`<div v-bind/>`, { onError })
expect(onError.mock.calls[0]).toMatchObject([
{
+import { vi } from 'vitest'
import {
baseParse as parse,
transform,
})
test('should handle parse error', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithExpressionTransform(`{{ a( }}`, { onError })
expect(onError.mock.calls[0][0].message).toMatch(
`Error parsing JavaScript expression: Unexpected token`
+import { vi } from 'vitest'
import {
CompilerOptions,
baseParse as parse,
})
test(`error on unexpected custom directive on <slot>`, () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const source = `<slot v-foo />`
parseWithSlots(source, { onError })
const index = source.indexOf('v-foo')
+import { vi } from 'vitest'
import {
baseParse as parse,
transform,
})
test('should error if no expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const node = parseWithVBind(`<div v-bind:arg />`, { onError })
const props = (node.codegenNode as VNodeCall).props as ObjectExpression
expect(onError.mock.calls[0][0]).toMatchObject({
+import { vi } from 'vitest'
import { baseParse as parse } from '../../src/parse'
import { transform } from '../../src/transform'
import { transformIf } from '../../src/transforms/vIf'
describe('errors', () => {
test('missing expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithForTransform('<span v-for />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('empty expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithForTransform('<span v-for="" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('invalid expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithForTransform('<span v-for="items" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('missing source', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithForTransform('<span v-for="item in" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('missing value', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithForTransform('<span v-for="in items" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('<template v-for> key placement', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithForTransform(
`
<template v-for="item in items">
+import { vi } from 'vitest'
import { baseParse as parse } from '../../src/parse'
import { transform } from '../../src/transform'
import { transformIf } from '../../src/transforms/vIf'
describe('errors', () => {
test('error on v-else missing adjacent v-if', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const { node: node1 } = parseWithIfTransform(`<div v-else/>`, { onError })
expect(onError.mock.calls[0]).toMatchObject([
})
test('error on v-else-if missing adjacent v-if or v-else-if', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const { node: node1 } = parseWithIfTransform(`<div v-else-if="foo"/>`, {
onError
})
test('error on user key', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
// dynamic
parseWithIfTransform(
`<div v-if="ok" :key="a + 1" /><div v-else :key="a + 1" />`,
+import { vi } from 'vitest'
import {
baseParse as parse,
transform,
describe('errors', () => {
test('missing expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithVModel('<span v-model />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('empty expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithVModel('<span v-model="" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('mal-formed expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithVModel('<span v-model="a + b" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('allow unicode', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithVModel('<span v-model="变.量" />', { onError })
expect(onError).toHaveBeenCalledTimes(0)
})
test('used on scope variable', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithVModel('<span v-for="i in list" v-model="i" />', {
onError,
prefixIdentifiers: true
})
test('used on props', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithVModel('<div v-model="p" />', {
onError,
bindingMetadata: {
+import { vi } from 'vitest'
import {
baseParse as parse,
CompilerOptions,
})
test('should error if no expression AND no modifier', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithVOn(`<div v-on:click />`, { onError })
expect(onError.mock.calls[0][0]).toMatchObject({
code: ErrorCodes.X_V_ON_NO_EXPRESSION,
})
test('should NOT error if no expression but has modifier', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithVOn(`<div v-on:click.prevent />`, { onError })
expect(onError).not.toHaveBeenCalled()
})
+import { vi } from 'vitest'
import {
CompilerOptions,
baseParse as parse,
describe('errors', () => {
test('error on extraneous children w/ named default slot', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const source = `<Comp><template #default>foo</template>bar</Comp>`
parseWithSlots(source, { onError })
const index = source.indexOf('bar')
})
test('error on duplicated slot names', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const source = `<Comp><template #foo></template><template #foo></template></Comp>`
parseWithSlots(source, { onError })
const index = source.lastIndexOf('#foo')
})
test('error on invalid mixed slot usage', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const source = `<Comp v-slot="foo"><template #foo></template></Comp>`
parseWithSlots(source, { onError })
const index = source.lastIndexOf('#foo')
})
test('error on v-slot usage on plain elements', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const source = `<div v-slot/>`
parseWithSlots(source, { onError })
const index = source.indexOf('v-slot')
+import { vi } from 'vitest'
import { compile } from '../../src'
describe('Transition multi children warnings', () => {
shouldWarn: boolean,
message = `<Transition> expects exactly one child element or component.`
) {
- const spy = jest.fn()
+ const spy = vi.fn()
compile(template.trim(), {
hoistStatic: true,
transformHoist: null,
+import { vi } from 'vitest'
import {
baseParse as parse,
transform,
})
it('should raise error and ignore children when v-html is present', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const ast = transformWithVHtml(`<div v-html="test">hello</div>`, {
onError
})
})
it('should raise error if has no expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
transformWithVHtml(`<div v-html></div>`, {
onError
})
+import { vi } from 'vitest'
import {
baseParse as parse,
transform,
describe('errors', () => {
test('plain elements with argument', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
transformWithModel('<input v-model:value="model" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('invalid element', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
transformWithModel('<span v-model="model" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
})
test('should allow usage on custom element', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const root = transformWithModel('<my-input v-model="model" />', {
onError,
isCustomElement: tag => tag.startsWith('my-')
})
test('should raise error if used file input element', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
transformWithModel(`<input type="file" v-model="test"/>`, {
onError
})
+import { vi } from 'vitest'
import {
baseParse as parse,
transform,
})
test('should raise error if has no expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
transformWithShow(`<div v-show/>`, { onError })
expect(onError).toHaveBeenCalledTimes(1)
+import { vi } from 'vitest'
import {
baseParse as parse,
transform,
})
it('should raise error and ignore children when v-text is present', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const ast = transformWithVText(`<div v-text="test">hello</div>`, {
onError
})
})
it('should raise error if has no expression', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
transformWithVText(`<div v-text></div>`, {
onError
})
-// Jest Snapshot v1, https://goo.gl/fbAQLP
+// Vitest Snapshot v1
exports[`$ unwrapping 1`] = `
"
+import { vi } from 'vitest'
import { reactive, effect, toRaw, isReactive } from '../../src'
describe('reactivity/collections', () => {
function coverCollectionFn(collection: Map<any, any>, fnName: string) {
- const spy = jest.fn()
+ const spy = vi.fn()
let proxy = reactive(collection)
;(collection as any)[fnName] = spy
return [proxy as any, spy]
it('should not observe non value changing mutations', () => {
let dummy
const map = reactive(new Map())
- const mapSpy = jest.fn(() => (dummy = map.get('key')))
+ const mapSpy = vi.fn(() => (dummy = map.get('key')))
effect(mapSpy)
expect(dummy).toBe(undefined)
it('should not be trigger when the value and the old value both are NaN', () => {
const map = reactive(new Map([['foo', NaN]]))
- const mapSpy = jest.fn(() => map.get('foo'))
+ const mapSpy = vi.fn(() => map.get('foo'))
effect(mapSpy)
map.set('foo', NaN)
expect(mapSpy).toHaveBeenCalledTimes(1)
// #877
it('should not trigger key iteration when setting existing keys', () => {
const map = reactive(new Map())
- const spy = jest.fn()
+ const spy = vi.fn()
effect(() => {
const keys = []
+import { vi } from 'vitest'
import { reactive, effect, isReactive, toRaw } from '../../src'
describe('reactivity/collections', () => {
function coverCollectionFn(collection: Set<any>, fnName: string) {
- const spy = jest.fn()
+ const spy = vi.fn()
let proxy = reactive(collection)
;(collection as any)[fnName] = spy
return [proxy as any, spy]
it('should not observe non value changing mutations', () => {
let dummy
const set = reactive(new Set())
- const setSpy = jest.fn(() => (dummy = set.has('value')))
+ const setSpy = vi.fn(() => (dummy = set.has('value')))
effect(setSpy)
expect(dummy).toBe(false)
let dummy
const key = {}
const set = reactive(new Set())
- const setSpy = jest.fn(() => (dummy = set.has(key)))
+ const setSpy = vi.fn(() => (dummy = set.has(key)))
effect(setSpy)
expect(dummy).toBe(false)
+import { vi } from 'vitest'
import { reactive, effect, toRaw, isReactive } from '../../src'
describe('reactivity/collections', () => {
let dummy
const key = {}
const map = reactive(new WeakMap())
- const mapSpy = jest.fn(() => (dummy = map.get(key)))
+ const mapSpy = vi.fn(() => (dummy = map.get(key)))
effect(mapSpy)
expect(dummy).toBe(undefined)
const map = new WeakMap()
const key = {}
map.set(key, NaN)
- const mapSpy = jest.fn(() => map.get(key))
+ const mapSpy = vi.fn(() => map.get(key))
effect(mapSpy)
map.set(key, NaN)
expect(mapSpy).toHaveBeenCalledTimes(1)
+import { vi } from 'vitest'
import { reactive, isReactive, effect, toRaw } from '../../src'
describe('reactivity/collections', () => {
let dummy
const value = {}
const set = reactive(new WeakSet())
- const setSpy = jest.fn(() => (dummy = set.has(value)))
+ const setSpy = vi.fn(() => (dummy = set.has(value)))
effect(setSpy)
expect(dummy).toBe(false)
+import { vi } from 'vitest'
import {
computed,
reactive,
it('should compute lazily', () => {
const value = reactive<{ foo?: number }>({})
- const getter = jest.fn(() => value.foo)
+ const getter = vi.fn(() => value.foo)
const cValue = computed(getter)
// lazy
it('should trigger effect when chained', () => {
const value = reactive({ foo: 0 })
- const getter1 = jest.fn(() => value.foo)
- const getter2 = jest.fn(() => {
+ const getter1 = vi.fn(() => value.foo)
+ const getter2 = vi.fn(() => {
return c1.value + 1
})
const c1 = computed(getter1)
it('should trigger effect when chained (mixed invocations)', () => {
const value = reactive({ foo: 0 })
- const getter1 = jest.fn(() => value.foo)
- const getter2 = jest.fn(() => {
+ const getter1 = vi.fn(() => value.foo)
+ const getter2 = vi.fn(() => {
return c1.value + 1
})
const c1 = computed(getter1)
it('debug: onTrack', () => {
let events: DebuggerEvent[] = []
- const onTrack = jest.fn((e: DebuggerEvent) => {
+ const onTrack = vi.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive({ foo: 1, bar: 2 })
it('debug: onTrigger', () => {
let events: DebuggerEvent[] = []
- const onTrigger = jest.fn((e: DebuggerEvent) => {
+ const onTrigger = vi.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive({ foo: 1 })
+import { vi } from 'vitest'
import { computed, deferredComputed, effect, ref } from '../src'
describe('deferred computed', () => {
test('should only trigger once on multiple mutations', async () => {
const src = ref(0)
const c = deferredComputed(() => src.value)
- const spy = jest.fn()
+ const spy = vi.fn()
effect(() => {
spy(c.value)
})
test('should not trigger if value did not change', async () => {
const src = ref(0)
const c = deferredComputed(() => src.value % 2)
- const spy = jest.fn()
+ const spy = vi.fn()
effect(() => {
spy(c.value)
})
})
test('chained computed trigger', async () => {
- const effectSpy = jest.fn()
- const c1Spy = jest.fn()
- const c2Spy = jest.fn()
+ const effectSpy = vi.fn()
+ const c1Spy = vi.fn()
+ const c2Spy = vi.fn()
const src = ref(0)
const c1 = deferredComputed(() => {
})
test('chained computed avoid re-compute', async () => {
- const effectSpy = jest.fn()
- const c1Spy = jest.fn()
- const c2Spy = jest.fn()
+ const effectSpy = vi.fn()
+ const c1Spy = vi.fn()
+ const c2Spy = vi.fn()
const src = ref(0)
const c1 = deferredComputed(() => {
})
test('chained computed value invalidation', async () => {
- const effectSpy = jest.fn()
- const c1Spy = jest.fn()
- const c2Spy = jest.fn()
+ const effectSpy = vi.fn()
+ const c1Spy = vi.fn()
+ const c2Spy = vi.fn()
const src = ref(0)
const c1 = deferredComputed(() => {
})
test('sync access of invalidated chained computed should not prevent final effect from running', async () => {
- const effectSpy = jest.fn()
- const c1Spy = jest.fn()
- const c2Spy = jest.fn()
+ const effectSpy = vi.fn()
+ const c1Spy = vi.fn()
+ const c2Spy = vi.fn()
const src = ref(0)
const c1 = deferredComputed(() => {
})
test('should not compute if deactivated before scheduler is called', async () => {
- const c1Spy = jest.fn()
+ const c1Spy = vi.fn()
const src = ref(0)
const c1 = deferredComputed(() => {
c1Spy()
+import { vi } from 'vitest'
import {
ref,
reactive,
describe('reactivity/effect', () => {
it('should run the passed function once (wrapped by a effect)', () => {
- const fnSpy = jest.fn(() => {})
+ const fnSpy = vi.fn(() => {})
effect(fnSpy)
expect(fnSpy).toHaveBeenCalledTimes(1)
})
let hasDummy, getDummy
const obj = reactive({ prop: 'value' })
- const getSpy = jest.fn(() => (getDummy = obj.prop))
- const hasSpy = jest.fn(() => (hasDummy = 'prop' in obj))
+ const getSpy = vi.fn(() => (getDummy = obj.prop))
+ const hasSpy = vi.fn(() => (hasDummy = 'prop' in obj))
effect(getSpy)
effect(hasSpy)
it('should avoid implicit infinite recursive loops with itself', () => {
const counter = reactive({ num: 0 })
- const counterSpy = jest.fn(() => counter.num++)
+ const counterSpy = vi.fn(() => counter.num++)
effect(counterSpy)
expect(counter.num).toBe(1)
expect(counterSpy).toHaveBeenCalledTimes(1)
it('should avoid infinite recursive loops when use Array.prototype.push/unshift/pop/shift', () => {
;(['push', 'unshift'] as const).forEach(key => {
const arr = reactive<number[]>([])
- const counterSpy1 = jest.fn(() => (arr[key] as any)(1))
- const counterSpy2 = jest.fn(() => (arr[key] as any)(2))
+ const counterSpy1 = vi.fn(() => (arr[key] as any)(1))
+ const counterSpy2 = vi.fn(() => (arr[key] as any)(2))
effect(counterSpy1)
effect(counterSpy2)
expect(arr.length).toBe(2)
})
;(['pop', 'shift'] as const).forEach(key => {
const arr = reactive<number[]>([1, 2, 3, 4])
- const counterSpy1 = jest.fn(() => (arr[key] as any)())
- const counterSpy2 = jest.fn(() => (arr[key] as any)())
+ const counterSpy1 = vi.fn(() => (arr[key] as any)())
+ const counterSpy2 = vi.fn(() => (arr[key] as any)())
effect(counterSpy1)
effect(counterSpy2)
expect(arr.length).toBe(2)
it('should allow explicitly recursive raw function loops', () => {
const counter = reactive({ num: 0 })
- const numSpy = jest.fn(() => {
+ const numSpy = vi.fn(() => {
counter.num++
if (counter.num < 10) {
numSpy()
it('should avoid infinite loops with other effects', () => {
const nums = reactive({ num1: 0, num2: 1 })
- const spy1 = jest.fn(() => (nums.num1 = nums.num2))
- const spy2 = jest.fn(() => (nums.num2 = nums.num1))
+ const spy1 = vi.fn(() => (nums.num1 = nums.num2))
+ const spy2 = vi.fn(() => (nums.num2 = nums.num1))
effect(spy1)
effect(spy2)
expect(nums.num1).toBe(1)
let dummy
const obj = reactive({ prop: 'value', run: false })
- const conditionalSpy = jest.fn(() => {
+ const conditionalSpy = vi.fn(() => {
dummy = obj.run ? obj.prop : 'other'
})
effect(conditionalSpy)
let dummy
const obj = reactive({ prop: 'value', run: true })
- const conditionalSpy = jest.fn(() => {
+ const conditionalSpy = vi.fn(() => {
dummy = obj.run ? obj.prop : 'other'
})
effect(conditionalSpy)
const input = reactive({ a: 1, b: 2, c: 0 })
const output = reactive({ fx1: 0, fx2: 0 })
- const fx1Spy = jest.fn(() => {
+ const fx1Spy = vi.fn(() => {
let result = 0
if (input.c < 2) result += input.a
if (input.c > 1) result += input.b
const fx1 = effect(fx1Spy)
- const fx2Spy = jest.fn(() => {
+ const fx2Spy = vi.fn(() => {
let result = 0
if (input.c > 1) result += input.a
if (input.c < 3) result += input.b
it('should not run multiple times for a single mutation', () => {
let dummy
const obj = reactive<Record<string, number>>({})
- const fnSpy = jest.fn(() => {
+ const fnSpy = vi.fn(() => {
for (const key in obj) {
dummy = obj[key]
}
const nums = reactive({ num1: 0, num2: 1, num3: 2 })
const dummy: any = {}
- const childSpy = jest.fn(() => (dummy.num1 = nums.num1))
+ const childSpy = vi.fn(() => (dummy.num1 = nums.num1))
const childeffect = effect(childSpy)
- const parentSpy = jest.fn(() => {
+ const parentSpy = vi.fn(() => {
dummy.num2 = nums.num2
childeffect()
dummy.num3 = nums.num3
it('scheduler', () => {
let dummy
let run: any
- const scheduler = jest.fn(() => {
+ const scheduler = vi.fn(() => {
run = runner
})
const obj = reactive({ foo: 1 })
it('events: onTrack', () => {
let events: DebuggerEvent[] = []
let dummy
- const onTrack = jest.fn((e: DebuggerEvent) => {
+ const onTrack = vi.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive({ foo: 1, bar: 2 })
it('events: onTrigger', () => {
let events: DebuggerEvent[] = []
let dummy
- const onTrigger = jest.fn((e: DebuggerEvent) => {
+ const onTrigger = vi.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive<{ foo?: number }>({ foo: 1 })
})
it('events: onStop', () => {
- const onStop = jest.fn()
+ const onStop = vi.fn()
const runner = effect(() => {}, {
onStop
})
const obj = reactive({
foo: NaN
})
- const fnSpy = jest.fn(() => obj.foo)
+ const fnSpy = vi.fn(() => obj.foo)
effect(fnSpy)
obj.foo = NaN
expect(fnSpy).toHaveBeenCalledTimes(1)
it('should not be triggered when set with the same proxy', () => {
const obj = reactive({ foo: 1 })
const observed: any = reactive({ obj })
- const fnSpy = jest.fn(() => observed.obj)
+ const fnSpy = vi.fn(() => observed.obj)
effect(fnSpy)
const obj2 = reactive({ foo: 1 })
const observed2: any = shallowReactive({ obj2 })
- const fnSpy2 = jest.fn(() => observed2.obj2)
+ const fnSpy2 = vi.fn(() => observed2.obj2)
effect(fnSpy2)
test('should work with readonly(reactive(Map))', () => {
const m = reactive(new Map())
const roM = readonly(m)
- const fnSpy = jest.fn(() => roM.get(1))
+ const fnSpy = vi.fn(() => roM.get(1))
effect(fnSpy)
expect(fnSpy).toHaveBeenCalledTimes(1)
const m = reactive(new Map())
m.set(key, 1)
const roM = readonly(m)
- const fnSpy = jest.fn(() => roM.get(key))
+ const fnSpy = vi.fn(() => roM.get(key))
effect(fnSpy)
expect(fnSpy).toHaveBeenCalledTimes(1)
test('should track hasOwnProperty', () => {
const obj: any = reactive({})
let has = false
- const fnSpy = jest.fn()
+ const fnSpy = vi.fn()
effect(() => {
fnSpy()
+import { vi } from 'vitest'
import { nextTick, watch, watchEffect } from '@vue/runtime-core'
import {
reactive,
describe('reactivity/effect/scope', () => {
it('should run', () => {
- const fnSpy = jest.fn(() => {})
+ const fnSpy = vi.fn(() => {})
new EffectScope().run(fnSpy)
expect(fnSpy).toHaveBeenCalledTimes(1)
})
})
it('should warn onScopeDispose() is called when there is no active effect scope', () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const scope = new EffectScope()
scope.run(() => {
onScopeDispose(spy)
it('test with higher level APIs', async () => {
const r = ref(1)
- const computedSpy = jest.fn()
- const watchSpy = jest.fn()
- const watchEffectSpy = jest.fn()
+ const computedSpy = vi.fn()
+ const watchSpy = vi.fn()
+ const watchEffectSpy = vi.fn()
let c: ComputedRef
const scope = new EffectScope()
+import { vi } from 'vitest'
import { reactive, isReactive, toRaw } from '../src/reactive'
import { ref, isRef } from '../src/ref'
import { effect } from '../src/effect'
test('delete on Array should not trigger length dependency', () => {
const arr = reactive([1, 2, 3])
- const fn = jest.fn()
+ const fn = vi.fn()
effect(() => {
fn(arr.length)
})
test('add existing index on Array should not trigger length dependency', () => {
const array = new Array(3)
const observed = reactive(array)
- const fn = jest.fn()
+ const fn = vi.fn()
effect(() => {
fn(observed.length)
})
test('add non-integer prop on Array should not trigger length dependency', () => {
const array: any[] & { x?: string } = new Array(3)
const observed = reactive(array)
- const fn = jest.fn()
+ const fn = vi.fn()
effect(() => {
fn(observed.length)
})
+import { vi } from 'vitest'
import {
ref,
effect,
const obj = reactive({ count: 0 })
const a = ref(obj)
- const spy1 = jest.fn(() => a.value)
+ const spy1 = vi.fn(() => a.value)
effect(spy1)
expect(spy1).toBeCalledTimes(1)
const b = shallowRef(obj)
- const spy2 = jest.fn(() => b.value)
+ const spy2 = vi.fn(() => b.value)
effect(spy2)
+import { vi } from 'vitest'
import {
isReactive,
isShallow,
// #1210
test('onTrack on called on objectSpread', () => {
- const onTrackFn = jest.fn()
+ const onTrackFn = vi.fn()
const shallowSet = shallowReactive(new Set())
let a
effect(
})
test('onTrack on called on objectSpread', () => {
- const onTrackFn = jest.fn()
+ const onTrackFn = vi.fn()
const shallowArray = shallowReactive([])
let a
effect(
+import { vi } from 'vitest'
import {
defineAsyncComponent,
h,
render: () => (toggle.value ? h(Foo) : null)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
render: () => (toggle.value ? h(Foo) : null)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
render: () => (toggle.value ? h(Foo) : null)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
render: () => h(Foo)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
render: () => h(Foo)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
const app = createApp({
render: () => h(Foo)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
await timeout(1)
const app = createApp({
render: () => h(Foo)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
await timeout(1)
})
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('loading')
render: () => h(Foo)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
expect(loaderCallCount).toBe(1)
render: () => h(Foo)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
expect(loaderCallCount).toBe(1)
render: () => h(Foo)
})
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
expect(loaderCallCount).toBe(1)
const updater = ref(0)
const vnodeHooks = {
- onVnodeBeforeMount: jest.fn(),
- onVnodeMounted: jest.fn(),
- onVnodeBeforeUpdate: jest.fn(),
- onVnodeUpdated: jest.fn(),
- onVnodeBeforeUnmount: jest.fn(),
- onVnodeUnmounted: jest.fn()
+ onVnodeBeforeMount: vi.fn(),
+ onVnodeMounted: vi.fn(),
+ onVnodeBeforeUpdate: vi.fn(),
+ onVnodeUpdated: vi.fn(),
+ onVnodeBeforeUnmount: vi.fn(),
+ onVnodeUnmounted: vi.fn()
}
const toggle = ref(true)
})
test('with KeepAlive', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
let resolve: (comp: Component) => void
const Foo = defineAsyncComponent(
+import { vi } from 'vitest'
import {
createApp,
h,
})
test('directive', () => {
- const spy1 = jest.fn()
- const spy2 = jest.fn()
- const spy3 = jest.fn()
+ const spy1 = vi.fn()
+ const spy2 = vi.fn()
+ const spy3 = vi.fn()
const Root = {
// local override
const error = new Error()
const count = ref(0)
- const handler = jest.fn((err, instance, info) => {
+ const handler = vi.fn((err, instance, info) => {
expect(err).toBe(error)
expect((instance as any).count).toBe(count.value)
expect(info).toBe(`render function`)
test('config.warnHandler', () => {
let ctx: any
- const handler = jest.fn((msg, instance, trace) => {
+ const handler = vi.fn((msg, instance, trace) => {
expect(msg).toMatch(`Component is missing template or render function`)
expect(instance).toBe(ctx.proxy)
expect(trace).toMatch(`Hello`)
})
describe('config.isNativeTag', () => {
- const isNativeTag = jest.fn(tag => tag === 'div')
+ const isNativeTag = vi.fn(tag => tag === 'div')
test('Component.name', () => {
const Root = {
+import { vi } from 'vitest'
import {
onBeforeMount,
h,
describe('api: lifecycle hooks', () => {
it('onBeforeMount', () => {
const root = nodeOps.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called before inner div is rendered
expect(serializeInner(root)).toBe(``)
})
it('onMounted', () => {
const root = nodeOps.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called after inner div is rendered
expect(serializeInner(root)).toBe(`<div></div>`)
})
it('onBeforeUpdate', async () => {
const count = ref(0)
const root = nodeOps.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called before inner div is updated
expect(serializeInner(root)).toBe(`<div>0</div>`)
})
it('state mutation in onBeforeUpdate', async () => {
const count = ref(0)
const root = nodeOps.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called before inner div is updated
expect(serializeInner(root)).toBe(`<div>0</div>`)
count.value++
})
- const renderSpy = jest.fn()
+ const renderSpy = vi.fn()
const Comp = {
setup() {
it('onUpdated', async () => {
const count = ref(0)
const root = nodeOps.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called after inner div is updated
expect(serializeInner(root)).toBe(`<div>1</div>`)
})
it('onBeforeUnmount', async () => {
const toggle = ref(true)
const root = nodeOps.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called before inner div is removed
expect(serializeInner(root)).toBe(`<div></div>`)
})
it('onUnmounted', async () => {
const toggle = ref(true)
const root = nodeOps.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called after inner div is removed
expect(serializeInner(root)).toBe(`<!---->`)
})
it('onBeforeUnmount in onMounted', async () => {
const toggle = ref(true)
const root = nodeOps.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called before inner div is removed
expect(serializeInner(root)).toBe(`<div></div>`)
})
it('onRenderTracked', () => {
const events: DebuggerEvent[] = []
- const onTrack = jest.fn((e: DebuggerEvent) => {
+ const onTrack = vi.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive({ foo: 1, bar: 2 })
it('onRenderTriggered', async () => {
const events: DebuggerEvent[] = []
- const onTrigger = jest.fn((e: DebuggerEvent) => {
+ const onTrigger = vi.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive<{
})
it('runs shared hook fn for each instance', async () => {
- const fn = jest.fn()
+ const fn = vi.fn()
const toggle = ref(true)
const Comp = {
setup() {
+import { vi } from 'vitest'
import {
h,
nodeOps,
function returnThis(this: any) {
return this
}
- const spyA = jest.fn(returnThis)
- const spyB = jest.fn(returnThis)
- const spyC = jest.fn(returnThis)
- const spyD = jest.fn(returnThis)
- const spyE = jest.fn(returnThis)
+ const spyA = vi.fn(returnThis)
+ const spyB = vi.fn(returnThis)
+ const spyC = vi.fn(returnThis)
+ const spyD = vi.fn(returnThis)
+ const spyE = vi.fn(returnThis)
let ctx: any
const Comp = {
const root = nodeOps.createElement('div')
render(h(Comp), root)
- function assertCall(spy: jest.Mock, callIndex: number, args: any[]) {
+ function assertCall(spy: vi.Mock, callIndex: number, args: any[]) {
expect(spy.mock.calls[callIndex].slice(0, 2)).toMatchObject(args)
expect(spy).toHaveReturnedWith(ctx)
}
function returnThis(this: any) {
return this
}
- const spyA = jest.fn(returnThis)
- const spyB = jest.fn(returnThis)
- const spyC = jest.fn(returnThis)
+ const spyA = vi.fn(returnThis)
+ const spyB = vi.fn(returnThis)
+ const spyC = vi.fn(returnThis)
let ctx: any
const Comp = {
const root = nodeOps.createElement('div')
render(h(Comp), root)
- function assertCall(spy: jest.Mock, callIndex: number, args: any[]) {
+ function assertCall(spy: vi.Mock, callIndex: number, args: any[]) {
expect(spy.mock.calls[callIndex].slice(0, 2)).toMatchObject(args)
expect(spy).toHaveReturnedWith(ctx)
}
methods: {}
}
- const watchSpy = jest.fn()
+ const watchSpy = vi.fn()
const mixin2 = {
watch: {
mixin3Data: watchSpy
+import { vi } from 'vitest'
import { ref, reactive } from '@vue/reactivity'
import {
renderToString,
it('context.emit', async () => {
const count = ref(0)
- const spy = jest.fn()
+ const spy = vi.fn()
const Parent = {
render: () =>
+import { vi } from 'vitest'
import {
ComponentInternalInstance,
createApp,
})
test('basic', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
let beforeInstance: ComponentInternalInstance | null = null
let afterInstance: ComponentInternalInstance | null = null
})
test('error handling', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
let beforeInstance: ComponentInternalInstance | null = null
let afterInstance: ComponentInternalInstance | null = null
+import { vi } from 'vitest'
import {
watch,
watchEffect,
it('watching single source: array', async () => {
const array = reactive([] as number[])
- const spy = jest.fn()
+ const spy = vi.fn()
watch(array, spy)
array.push(1)
await nextTick()
})
it('should not fire if watched getter result did not change', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const n = ref(0)
watch(() => n.value % 2, spy)
it('cleanup registration (effect)', async () => {
const state = reactive({ count: 0 })
- const cleanup = jest.fn()
+ const cleanup = vi.fn()
let dummy
const stop = watchEffect(onCleanup => {
onCleanup(cleanup)
it('cleanup registration (with source)', async () => {
const count = ref(0)
- const cleanup = jest.fn()
+ const cleanup = vi.fn()
let dummy
const stop = watch(count, (count, prevCount, onCleanup) => {
onCleanup(cleanup)
let callCount = 0
let result1
let result2
- const assertion = jest.fn((count, count2Value) => {
+ const assertion = vi.fn((count, count2Value) => {
callCount++
// on mount, the watcher callback should be called before DOM render
// on update, should be called before the count is updated
it('flush timing: post', async () => {
const count = ref(0)
let result
- const assertion = jest.fn(count => {
+ const assertion = vi.fn(count => {
result = serializeInner(root) === `${count}`
})
it('watchPostEffect', async () => {
const count = ref(0)
let result
- const assertion = jest.fn(count => {
+ const assertion = vi.fn(count => {
result = serializeInner(root) === `${count}`
})
let callCount = 0
let result1
let result2
- const assertion = jest.fn(count => {
+ const assertion = vi.fn(count => {
callCount++
// on mount, the watcher callback should be called before DOM render
// on update, should be called before the count is updated
let callCount = 0
let result1
let result2
- const assertion = jest.fn(count => {
+ const assertion = vi.fn(count => {
callCount++
// on mount, the watcher callback should be called before DOM render
// on update, should be called before the count is updated
it('should not fire on component unmount w/ flush: post', async () => {
const toggle = ref(true)
- const cb = jest.fn()
+ const cb = vi.fn()
const Comp = {
setup() {
watch(toggle, cb, { flush: 'post' })
// #2291
it('should not fire on component unmount w/ flush: pre', async () => {
const toggle = ref(true)
- const cb = jest.fn()
+ const cb = vi.fn()
const Comp = {
setup() {
watch(toggle, cb, { flush: 'pre' })
it('immediate', async () => {
const count = ref(0)
- const cb = jest.fn()
+ const cb = vi.fn()
watch(count, cb, { immediate: true })
expect(cb).toHaveBeenCalledTimes(1)
count.value++
it('immediate: triggers when initial value is null', async () => {
const state = ref(null)
- const spy = jest.fn()
+ const spy = vi.fn()
watch(() => state.value, spy, { immediate: true })
expect(spy).toHaveBeenCalled()
})
it('immediate: triggers when initial value is undefined', async () => {
const state = ref()
- const spy = jest.fn()
+ const spy = vi.fn()
watch(() => state.value, spy, { immediate: true })
expect(spy).toHaveBeenCalledWith(undefined, undefined, expect.any(Function))
state.value = 3
it('warn and not respect deep option when using effect', async () => {
const arr = ref([1, [2]])
- const spy = jest.fn()
+ const spy = vi.fn()
watchEffect(
() => {
spy()
it('onTrack', async () => {
const events: DebuggerEvent[] = []
let dummy
- const onTrack = jest.fn((e: DebuggerEvent) => {
+ const onTrack = vi.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive({ foo: 1, bar: 2 })
it('onTrigger', async () => {
const events: DebuggerEvent[] = []
let dummy
- const onTrigger = jest.fn((e: DebuggerEvent) => {
+ const onTrigger = vi.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive<{ foo?: number }>({ foo: 1 })
test('should force trigger on triggerRef when watching multiple sources: shallow ref array', async () => {
const v = shallowRef([] as any)
- const spy = jest.fn()
+ const spy = vi.fn()
watch([v], () => {
spy()
})
// #2125
test('watchEffect should not recursively trigger itself', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const price = ref(10)
const history = ref<number[]>([])
watchEffect(() => {
// #2231
test('computed refs should not trigger watch if value has no change', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const source = ref(0)
const price = computed(() => source.value === 0)
watch(price, spy)
test('this.$watch should pass `this.proxy` to watch source as the first argument ', () => {
let instance: any
- const source = jest.fn()
+ const source = vi.fn()
const Comp = defineComponent({
render() {},
})
test('should not leak `this.proxy` to setup()', () => {
- const source = jest.fn()
+ const source = vi.fn()
const Comp = defineComponent({
render() {},
test('pre watcher callbacks should not track dependencies', async () => {
const a = ref(0)
const b = ref(0)
- const updated = jest.fn()
+ const updated = vi.fn()
const Child = defineComponent({
props: ['a'],
})
test('watching keypath', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const Comp = defineComponent({
render() {},
data() {
it('watching sources: ref<any[]>', async () => {
const foo = ref([1])
- const spy = jest.fn()
+ const spy = vi.fn()
watch(foo, () => {
spy()
})
// Note: emits and listener fallthrough is tested in
// ./rendererAttrsFallthrough.spec.ts.
+import { vi } from 'vitest'
import {
render,
defineComponent,
}
})
- const onfoo = jest.fn()
- const onBar = jest.fn()
- const onBaz = jest.fn()
+ const onfoo = vi.fn()
+ const onBar = vi.fn()
+ const onBaz = vi.fn()
const Comp = () => h(Foo, { onfoo, onBar, ['on!baz']: onBaz })
render(h(Comp), nodeOps.createElement('div'))
}
})
- const fooSpy = jest.fn()
+ const fooSpy = vi.fn()
const Comp = () =>
h(Foo, {
onTestEvent: fooSpy
}
})
- const fooSpy = jest.fn()
+ const fooSpy = vi.fn()
const Comp = () =>
h(Foo, {
'onTest-event': fooSpy
}
})
- const fooSpy = jest.fn()
- const barSpy = jest.fn()
+ const fooSpy = vi.fn()
+ const barSpy = vi.fn()
const Comp = () =>
// simulate v-on="obj" usage
h(
}
})
- const fooSpy = jest.fn()
- const barSpy = jest.fn()
+ const fooSpy = vi.fn()
+ const barSpy = vi.fn()
const Comp = () =>
h(Foo, {
'onUpdate:fooProp': fooSpy,
}
})
- const fn1 = jest.fn()
- const fn2 = jest.fn()
+ const fn1 = vi.fn()
+ const fn2 = vi.fn()
const App = {
setup() {
this.$emit('bar')
}
})
- const fn = jest.fn()
- const barFn = jest.fn()
+ const fn = vi.fn()
+ const barFn = vi.fn()
render(
h(Foo, {
onFooOnce: fn,
this.$emit('foo')
}
})
- const onFoo = jest.fn()
- const onFooOnce = jest.fn()
+ const onFoo = vi.fn()
+ const onFooOnce = vi.fn()
render(
h(Foo, {
onFoo,
}
})
- const fn1 = jest.fn()
- const fn2 = jest.fn()
+ const fn1 = vi.fn()
+ const fn2 = vi.fn()
const Comp = () =>
h(Foo, {
}
})
- const fn1 = jest.fn()
- const fn2 = jest.fn()
+ const fn1 = vi.fn()
+ const fn2 = vi.fn()
const Comp = () =>
h(Foo, {
}
})
- const fn1 = jest.fn()
- const fn2 = jest.fn()
+ const fn1 = vi.fn()
+ const fn2 = vi.fn()
const Comp = () =>
h(Foo, {
}
})
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = () =>
h(Foo, {
modelValue: null,
})
test('does not emit after unmount', async () => {
- const fn = jest.fn()
+ const fn = vi.fn()
const Foo = defineComponent({
emits: ['closing'],
async beforeUnmount() {
+import { vi } from 'vitest'
import {
ComponentInternalInstance,
getCurrentInstance,
test('default value', () => {
let proxy: any
- const defaultFn = jest.fn(() => ({ a: 1 }))
- const defaultBaz = jest.fn(() => ({ b: 1 }))
+ const defaultFn = vi.fn(() => ({ a: 1 }))
+ const defaultBaz = vi.fn(() => ({ b: 1 }))
const Comp = {
props: {
// #3288
test('declared prop key should be present even if not passed', async () => {
let initialKeys: string[] = []
- const changeSpy = jest.fn()
+ const changeSpy = vi.fn()
const passFoo = ref(false)
const Comp = {
+import { vi } from 'vitest'
import {
h,
render,
// attaching jest spy, triggers the getter once, cache it and override the property.
// also uses Object.defineProperty
- const spy = jest.spyOn(instanceProxy, 'toggle')
+ const spy = vi.spyOn(instanceProxy, 'toggle')
expect(getCalledTimes).toEqual(3)
// expect getter to not evaluate the jest spy caches its value
+import { vi } from 'vitest'
import {
ref,
render,
test('should respect $stable flag', async () => {
const flag1 = ref(1)
const flag2 = ref(2)
- const spy = jest.fn()
+ const spy = vi.fn()
const Child = () => {
spy()
+import { vi } from 'vitest'
import {
nodeOps,
render,
doneLeave: {}
}
const props: BaseTransitionProps = {
- onBeforeEnter: jest.fn(el => {
+ onBeforeEnter: vi.fn(el => {
if (!extra.persisted && !withKeepAlive) {
expect(el.parentNode).toBeNull()
}
}),
- onEnter: jest.fn((el, done) => {
+ onEnter: vi.fn((el, done) => {
cbs.doneEnter[serialize(el as TestElement)] = done
}),
- onAfterEnter: jest.fn(),
- onEnterCancelled: jest.fn(),
- onBeforeLeave: jest.fn(),
- onLeave: jest.fn((el, done) => {
+ onAfterEnter: vi.fn(),
+ onEnterCancelled: vi.fn(),
+ onBeforeLeave: vi.fn(),
+ onLeave: vi.fn((el, done) => {
cbs.doneLeave[serialize(el as TestElement)] = done
}),
- onAfterLeave: jest.fn(),
- onLeaveCancelled: jest.fn(),
- onBeforeAppear: jest.fn(),
- onAppear: jest.fn((el, done) => {
+ onAfterLeave: vi.fn(),
+ onLeaveCancelled: vi.fn(),
+ onBeforeAppear: vi.fn(),
+ onAppear: vi.fn((el, done) => {
cbs.doneEnter[serialize(el as TestElement)] = done
}),
- onAfterAppear: jest.fn(),
- onAppearCancelled: jest.fn(),
+ onAfterAppear: vi.fn(),
+ onAppearCancelled: vi.fn(),
...extra
}
return {
}
function assertCalledWithEl(fn: any, expected: string, callIndex = 0) {
- expect(serialize((fn as jest.Mock).mock.calls[callIndex][0])).toBe(expected)
+ expect(serialize((fn as vi.Mock).mock.calls[callIndex][0])).toBe(expected)
}
interface ToggleOptions {
+import { vi } from 'vitest'
import {
h,
TestElement,
render(this: any) {
return h('div', this.msg)
},
- created: jest.fn(),
- mounted: jest.fn(),
- activated: jest.fn(),
- deactivated: jest.fn(),
- unmounted: jest.fn()
+ created: vi.fn(),
+ mounted: vi.fn(),
+ activated: vi.fn(),
+ deactivated: vi.fn(),
+ unmounted: vi.fn()
}
two = {
name: 'two',
render(this: any) {
return h('div', this.msg)
},
- created: jest.fn(),
- mounted: jest.fn(),
- activated: jest.fn(),
- deactivated: jest.fn(),
- unmounted: jest.fn()
+ created: vi.fn(),
+ mounted: vi.fn(),
+ activated: vi.fn(),
+ deactivated: vi.fn(),
+ unmounted: vi.fn()
}
views = {
one,
render(this: any) {
return h('div', this.msg)
},
- activated: jest.fn()
+ activated: vi.fn()
}
const one = {
name: 'one',
})
test('max', async () => {
- const spyAC = jest.fn()
- const spyBC = jest.fn()
- const spyCC = jest.fn()
- const spyAA = jest.fn()
- const spyBA = jest.fn()
- const spyCA = jest.fn()
- const spyADA = jest.fn()
- const spyBDA = jest.fn()
- const spyCDA = jest.fn()
- const spyAUM = jest.fn()
- const spyBUM = jest.fn()
- const spyCUM = jest.fn()
+ const spyAC = vi.fn()
+ const spyBC = vi.fn()
+ const spyCC = vi.fn()
+ const spyAA = vi.fn()
+ const spyBA = vi.fn()
+ const spyCA = vi.fn()
+ const spyADA = vi.fn()
+ const spyBDA = vi.fn()
+ const spyCDA = vi.fn()
+ const spyAUM = vi.fn()
+ const spyBUM = vi.fn()
+ const spyCUM = vi.fn()
function assertCount(calls: number[]) {
expect([
async function assertAnonymous(include: boolean) {
const one = {
name: 'one',
- created: jest.fn(),
+ created: vi.fn(),
render: () => 'one'
}
const two = {
// anonymous
- created: jest.fn(),
+ created: vi.fn(),
render: () => 'two'
}
test('should not destroy active instance when pruning cache', async () => {
const Foo = {
render: () => 'foo',
- unmounted: jest.fn()
+ unmounted: vi.fn()
}
const includeRef = ref(['foo'])
const App = {
}
})
- const spyMounted = jest.fn()
- const spyUnmounted = jest.fn()
+ const spyMounted = vi.fn()
+ const spyUnmounted = vi.fn()
const RouterView = defineComponent({
setup(_, { slots }) {
// #4976
test('handle error in async onActivated', async () => {
const err = new Error('foo')
- const handler = jest.fn()
+ const handler = vi.fn()
const app = createApp({
setup() {
// #3648
test('should avoid unmount later included components', async () => {
- const unmountedA = jest.fn()
- const mountedA = jest.fn()
- const activatedA = jest.fn()
- const deactivatedA = jest.fn()
- const unmountedB = jest.fn()
- const mountedB = jest.fn()
+ const unmountedA = vi.fn()
+ const mountedA = vi.fn()
+ const activatedA = vi.fn()
+ const deactivatedA = vi.fn()
+ const unmountedB = vi.fn()
+ const mountedB = vi.fn()
const A = {
name: 'A',
+import { vi } from 'vitest'
import {
h,
ref,
}
})
- const onFallback = jest.fn()
- const onResolve = jest.fn()
- const onPending = jest.fn()
+ const onFallback = vi.fn()
+ const onResolve = vi.fn()
+ const onPending = vi.fn()
const show = ref(true)
const Comp = {
}
})
- const onResolve = jest.fn()
+ const onResolve = vi.fn()
const Comp = {
setup() {
test('unmount suspense after resolve', async () => {
const toggle = ref(true)
- const unmounted = jest.fn()
+ const unmounted = vi.fn()
const Async = defineAsyncComponent({
setup() {
test('unmount suspense before resolve', async () => {
const toggle = ref(true)
- const mounted = jest.fn()
- const unmounted = jest.fn()
+ const mounted = vi.fn()
+ const unmounted = vi.fn()
const Async = defineAsyncComponent({
setup() {
+import { vi } from 'vitest'
import {
nodeOps,
serializeInner,
const root = nodeOps.createElement('div')
const toggle = ref(true)
const dir = {
- mounted: jest.fn(),
- unmounted: jest.fn()
+ mounted: vi.fn(),
+ unmounted: vi.fn()
}
const app = createApp({
+import { vi } from 'vitest'
import {
h,
withDirectives,
expect(binding.modifiers && binding.modifiers.ok).toBe(true)
}
- const beforeMount = jest.fn(((el, binding, vnode, prevVNode) => {
+ const beforeMount = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
// should not be inserted yet
expect(el.parentNode).toBe(null)
expect(prevVNode).toBe(null)
}) as DirectiveHook)
- const mounted = jest.fn(((el, binding, vnode, prevVNode) => {
+ const mounted = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
// should be inserted now
expect(el.parentNode).toBe(root)
expect(prevVNode).toBe(null)
}) as DirectiveHook)
- const beforeUpdate = jest.fn(((el, binding, vnode, prevVNode) => {
+ const beforeUpdate = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
expect(el.parentNode).toBe(root)
expect(root.children[0]).toBe(el)
expect(prevVNode).toBe(_prevVnode)
}) as DirectiveHook)
- const updated = jest.fn(((el, binding, vnode, prevVNode) => {
+ const updated = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
expect(el.parentNode).toBe(root)
expect(root.children[0]).toBe(el)
expect(prevVNode).toBe(_prevVnode)
}) as DirectiveHook)
- const beforeUnmount = jest.fn(((el, binding, vnode, prevVNode) => {
+ const beforeUnmount = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
// should be removed now
expect(el.parentNode).toBe(root)
expect(prevVNode).toBe(null)
}) as DirectiveHook)
- const unmounted = jest.fn(((el, binding, vnode, prevVNode) => {
+ const unmounted = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
// should have been removed
expect(el.parentNode).toBe(null)
expect(binding.modifiers && binding.modifiers.ok).toBe(true)
}
- const fn = jest.fn(((el, binding, vnode, prevVNode) => {
+ const fn = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
expect(el.parentNode).toBe(root)
expect(binding.modifiers && binding.modifiers.ok).toBe(true)
}
- const beforeMount = jest.fn(((el, binding, vnode, prevVNode) => {
+ const beforeMount = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
// should not be inserted yet
expect(el.parentNode).toBe(null)
expect(prevVNode).toBe(null)
}) as DirectiveHook)
- const mounted = jest.fn(((el, binding, vnode, prevVNode) => {
+ const mounted = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
// should be inserted now
expect(el.parentNode).toBe(root)
expect(prevVNode).toBe(null)
}) as DirectiveHook)
- const beforeUpdate = jest.fn(((el, binding, vnode, prevVNode) => {
+ const beforeUpdate = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
expect(el.parentNode).toBe(root)
expect(root.children[0]).toBe(el)
expect(prevVNode!.type).toBe(_prevVnode!.type)
}) as DirectiveHook)
- const updated = jest.fn(((el, binding, vnode, prevVNode) => {
+ const updated = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
expect(el.parentNode).toBe(root)
expect(root.children[0]).toBe(el)
expect(prevVNode!.type).toBe(_prevVnode!.type)
}) as DirectiveHook)
- const beforeUnmount = jest.fn(((el, binding, vnode, prevVNode) => {
+ const beforeUnmount = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
// should be removed now
expect(el.parentNode).toBe(root)
expect(prevVNode).toBe(null)
}) as DirectiveHook)
- const unmounted = jest.fn(((el, binding, vnode, prevVNode) => {
+ const unmounted = vi.fn(((el, binding, vnode, prevVNode) => {
expect(el.tag).toBe('div')
// should have been removed
expect(el.parentNode).toBe(null)
// #2298
it('directive merging on component root', () => {
const d1 = {
- mounted: jest.fn()
+ mounted: vi.fn()
}
const d2 = {
- mounted: jest.fn()
+ mounted: vi.fn()
}
const Comp = {
render() {
test('should disable tracking inside directive lifecycle hooks', async () => {
const count = ref(0)
const text = ref('')
- const beforeUpdate = jest.fn(() => count.value++)
+ const beforeUpdate = vi.fn(() => count.value++)
const App = {
render() {
test('should not throw with unknown directive', async () => {
const d1 = {
- mounted: jest.fn()
+ mounted: vi.fn()
}
const App = {
name: 'App',
+import { vi } from 'vitest'
import {
onMounted,
onErrorCaptured,
describe('error handling', () => {
test('propagation', () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('propagation stoppage', () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('async error handling', async () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('error thrown in onErrorCaptured', () => {
const err = new Error('foo')
const err2 = new Error('bar')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('setup function', () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
// the options API initialization process instead of by the renderer.
test('in created/beforeCreate hook', () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('in render function', () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
const ref = () => {
throw err
}
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('in effect', () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('in watch getter', () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('in watch callback', async () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('in effect cleanup', async () => {
const err = new Error('foo')
const count = ref(0)
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('in component event handler via emit', () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('in component event handler via emit (async)', async () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
test('in component event handler via emit (async + array)', async () => {
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const res: Promise<any>[] = []
const createAsyncHandler = (p: Promise<any>) => () => {
})
it('should warn unhandled', () => {
- const groupCollapsed = jest.spyOn(console, 'groupCollapsed')
+ const groupCollapsed = vi.spyOn(console, 'groupCollapsed')
groupCollapsed.mockImplementation(() => {})
- const log = jest.spyOn(console, 'log')
+ const log = vi.spyOn(console, 'log')
log.mockImplementation(() => {})
const err = new Error('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = {
setup() {
const error2 = new Error('error2')
const error3 = new Error('error3')
const error4 = new Error('error4')
- const handler = jest.fn()
+ const handler = vi.fn()
const app = createApp({
setup() {
+import { vi } from 'vitest'
import { HMRRuntime } from '../src/hmr'
import '../src/hmr'
import { ComponentOptions, InternalRenderFunction } from '../src/component'
test('reload', async () => {
const root = nodeOps.createElement('div')
const childId = 'test3-child'
- const unmountSpy = jest.fn()
- const mountSpy = jest.fn()
+ const unmountSpy = vi.fn()
+ const mountSpy = vi.fn()
const Child: ComponentOptions = {
__hmrId: childId,
test('reload KeepAlive slot', async () => {
const root = nodeOps.createElement('div')
const childId = 'test-child-keep-alive'
- const unmountSpy = jest.fn()
- const mountSpy = jest.fn()
- const activeSpy = jest.fn()
- const deactiveSpy = jest.fn()
+ const unmountSpy = vi.fn()
+ const mountSpy = vi.fn()
+ const activeSpy = vi.fn()
+ const deactiveSpy = vi.fn()
const Child: ComponentOptions = {
__hmrId: childId,
test('reload class component', async () => {
const root = nodeOps.createElement('div')
const childId = 'test4-child'
- const unmountSpy = jest.fn()
- const mountSpy = jest.fn()
+ const unmountSpy = vi.fn()
+ const mountSpy = vi.fn()
class Child {
static __vccOpts: ComponentOptions = {
// #4174
test('with global mixins', async () => {
const childId = 'hmr-global-mixin'
- const createSpy1 = jest.fn()
- const createSpy2 = jest.fn()
+ const createSpy1 = vi.fn()
+ const createSpy2 = vi.fn()
const Child: ComponentOptions = {
__hmrId: childId,
+import { vi } from 'vitest'
import {
createSSRApp,
h,
test('element with elements children', async () => {
const msg = ref('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const { vnode, container } = mountWithHydration(
'<div><span>foo</span><span class="foo"></span></div>',
() =>
test('Fragment', async () => {
const msg = ref('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const { vnode, container } = mountWithHydration(
'<div><!--[--><span>foo</span><!--[--><span class="foo"></span><!--]--><!--]--></div>',
() =>
test('Teleport', async () => {
const msg = ref('foo')
- const fn = jest.fn()
+ const fn = vi.fn()
const teleportContainer = document.createElement('div')
teleportContainer.id = 'teleport'
teleportContainer.innerHTML = `<span>foo</span><span class="foo"></span><!--teleport anchor-->`
test('Teleport (multiple + integration)', async () => {
const msg = ref('foo')
- const fn1 = jest.fn()
- const fn2 = jest.fn()
+ const fn1 = vi.fn()
+ const fn2 = vi.fn()
const Comp = () => [
h(Teleport, { to: '#teleport2' }, [
test('Teleport (disabled)', async () => {
const msg = ref('foo')
- const fn1 = jest.fn()
- const fn2 = jest.fn()
+ const fn1 = vi.fn()
+ const fn2 = vi.fn()
const Comp = () => [
h('div', 'foo'),
// compile SSR + client render fn from the same template & hydrate
test('full compiler integration', async () => {
const mounted: string[] = []
- const log = jest.fn()
+ const log = vi.fn()
const toggle = ref(true)
const Child = {
container.innerHTML = await renderToString(h(App))
// hydrate
const app = createSSRApp(App)
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(container)
// assert interactions
// parent button click
container.innerHTML = await renderToString(h(App))
// hydrate
const app = createSSRApp(App)
- const handler = (app.config.errorHandler = jest.fn())
+ const handler = (app.config.errorHandler = vi.fn())
app.mount(container)
// assert interactions
// parent blur event
}
})
- const done = jest.fn()
+ const done = vi.fn()
const App = {
template: `
<Suspense @resolve="done">
})
test('async component', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const Comp = () =>
h(
'button',
// using DOM renderer because this case is mostly DOM-specific
+import { vi } from 'vitest'
import {
h,
render,
describe('attribute fallthrough', () => {
it('should allow attrs to fallthrough', async () => {
- const click = jest.fn()
- const childUpdated = jest.fn()
+ const click = vi.fn()
+ const childUpdated = vi.fn()
const Hello = {
setup() {
})
it('should only allow whitelisted fallthrough on functional component with optional props', async () => {
- const click = jest.fn()
- const childUpdated = jest.fn()
+ const click = vi.fn()
+ const childUpdated = vi.fn()
const count = ref(0)
})
it('should allow all attrs on functional component with declared props', async () => {
- const click = jest.fn()
- const childUpdated = jest.fn()
+ const click = vi.fn()
+ const childUpdated = vi.fn()
const count = ref(0)
})
it('should fallthrough for nested components', async () => {
- const click = jest.fn()
- const childUpdated = jest.fn()
- const grandChildUpdated = jest.fn()
+ const click = vi.fn()
+ const childUpdated = vi.fn()
+ const grandChildUpdated = vi.fn()
const Hello = {
setup() {
})
it('should dedupe same listeners when $attrs is used during render', () => {
- const click = jest.fn()
+ const click = vi.fn()
const count = ref(0)
function inc() {
}
})
- const onClick = jest.fn()
+ const onClick = vi.fn()
const App = {
render() {
return h(Child, {
}
Child.emits = ['click']
- const onClick = jest.fn()
+ const onClick = vi.fn()
const App = {
render() {
return h(Child, {
})
it('should support fallthrough for fragments with single element + comments', () => {
- const click = jest.fn()
+ const click = vi.fn()
const Hello = {
setup() {
it('should not fallthrough v-model listeners with corresponding declared prop', () => {
let textFoo = ''
let textBar = ''
- const click = jest.fn()
+ const click = vi.fn()
const App = defineComponent({
setup() {
+import { vi } from 'vitest'
import {
ref,
h,
it('should not update Component if only changed props are declared emit listeners', () => {
const Comp1 = {
emits: ['foo'],
- updated: jest.fn(),
+ updated: vi.fn(),
render: () => null
}
const root = nodeOps.createElement('div')
function returnThis(this: any, _arg: any) {
return this
}
- const propWatchSpy = jest.fn(returnThis)
- const dataWatchSpy = jest.fn(returnThis)
+ const propWatchSpy = vi.fn(returnThis)
+ const dataWatchSpy = vi.fn(returnThis)
let instance: any
const Comp = {
props: {
setup() {
return () => h(Child)
},
- updated: jest.fn()
+ updated: vi.fn()
}
const root = nodeOps.createElement('div')
test('child component props update should not lead to double update', async () => {
const text = ref(0)
- const spy = jest.fn()
+ const spy = vi.fn()
const App = {
render() {
+import { vi } from 'vitest'
import {
h,
Fragment,
})
test('PatchFlags: PatchFlags.NEED_PATCH', async () => {
- const spyMounted = jest.fn()
- const spyUpdated = jest.fn()
+ const spyMounted = vi.fn()
+ const spyUpdated = vi.fn()
const count = ref(0)
const Comp = {
setup() {
// When unmounting (1), we know we are in optimized mode so no need to further
// traverse unmount its children
test('should not perform unnecessary unmount traversals', () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const Child = {
setup() {
onBeforeUnmount(spy)
// #2444
// `KEYED_FRAGMENT` and `UNKEYED_FRAGMENT` always need to diff its children
test('non-stable Fragment always need to diff its children', () => {
- const spyA = jest.fn()
- const spyB = jest.fn()
+ const spyA = vi.fn()
+ const spyB = vi.fn()
const ChildA = {
setup() {
onBeforeUnmount(spyA)
// #4183
test('should not take unmount children fast path /w Suspense', async () => {
const show = ref(true)
- const spyUnmounted = jest.fn()
+ const spyUnmounted = vi.fn()
const Parent = {
setup(props: any, { slots }: SetupContext) {
+import { vi } from 'vitest'
import {
ref,
nodeOps,
it('function ref mount', () => {
const root = nodeOps.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
const Comp = defineComponent(() => () => h('div', { ref: fn }))
render(h(Comp), root)
it('function ref update', async () => {
const root = nodeOps.createElement('div')
- const fn1 = jest.fn()
- const fn2 = jest.fn()
+ const fn1 = vi.fn()
+ const fn2 = vi.fn()
const fn = ref(fn1)
const Comp = defineComponent(() => () => h('div', { ref: fn.value }))
it('function ref unmount', async () => {
const root = nodeOps.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
const toggle = ref(true)
const Comp = defineComponent(
test('string ref inside slots', async () => {
const root = nodeOps.createElement('div')
- const spy = jest.fn()
+ const spy = vi.fn()
const Child = {
render(this: any) {
return this.$slots.default()
// #1834
test('exchange refs', async () => {
const refToggle = ref(false)
- const spy = jest.fn()
+ const spy = vi.fn()
const Comp = {
render(this: any) {
// #1789
test('toggle the same ref to different elements', async () => {
const refToggle = ref(false)
- const spy = jest.fn()
+ const spy = vi.fn()
const Comp = {
render(this: any) {
+import { vi } from 'vitest'
import {
queueJob,
nextTick,
// #3806
it('queue preFlushCb inside postFlushCb', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const cb = () => spy()
cb.pre = true
queuePostFlushCb(() => {
// #910
test('should not run stopped reactive effects', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
// simulate parent component that toggles child
const job1 = () => {
})
it('flushPreFlushCbs inside a pre job', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const job = () => {
spy()
flushPreFlushCbs()
+import { vi } from 'vitest'
import {
createBlock,
createVNode,
})
describe('children normalization', () => {
- const nop = jest.fn
+ const nop = vi.fn
test('null', () => {
const vnode = createVNode('p', null, null)
+import { vi } from 'vitest'
import {
h,
render,
test('should work on element', () => {
const hooks: VNodeProps = {
- onVnodeBeforeMount: jest.fn(),
- onVnodeMounted: jest.fn(),
- onVnodeBeforeUpdate: jest.fn(vnode => {
+ onVnodeBeforeMount: vi.fn(),
+ onVnodeMounted: vi.fn(),
+ onVnodeBeforeUpdate: vi.fn(vnode => {
expect((vnode.el as TestElement).children[0]).toMatchObject({
type: NodeTypes.TEXT,
text: 'foo'
})
}),
- onVnodeUpdated: jest.fn(vnode => {
+ onVnodeUpdated: vi.fn(vnode => {
expect((vnode.el as TestElement).children[0]).toMatchObject({
type: NodeTypes.TEXT,
text: 'bar'
})
}),
- onVnodeBeforeUnmount: jest.fn(),
- onVnodeUnmounted: jest.fn()
+ onVnodeBeforeUnmount: vi.fn(),
+ onVnodeUnmounted: vi.fn()
}
assertHooks(hooks, h('div', hooks, 'foo'), h('div', hooks, 'bar'))
const Comp = (props: { msg: string }) => props.msg
const hooks: VNodeProps = {
- onVnodeBeforeMount: jest.fn(),
- onVnodeMounted: jest.fn(),
- onVnodeBeforeUpdate: jest.fn(vnode => {
+ onVnodeBeforeMount: vi.fn(),
+ onVnodeMounted: vi.fn(),
+ onVnodeBeforeUpdate: vi.fn(vnode => {
expect(vnode.el as TestElement).toMatchObject({
type: NodeTypes.TEXT,
text: 'foo'
})
}),
- onVnodeUpdated: jest.fn(vnode => {
+ onVnodeUpdated: vi.fn(vnode => {
expect(vnode.el as TestElement).toMatchObject({
type: NodeTypes.TEXT,
text: 'bar'
})
}),
- onVnodeBeforeUnmount: jest.fn(),
- onVnodeUnmounted: jest.fn()
+ onVnodeBeforeUnmount: vi.fn(),
+ onVnodeUnmounted: vi.fn()
}
assertHooks(
ComponentInternalInstance,
currentInstance,
isInSSRComponentSetup,
- LifecycleHooks,
setCurrentInstance,
unsetCurrentInstance
} from './component'
import { warn } from './warning'
import { toHandlerKey } from '@vue/shared'
import { DebuggerEvent, pauseTracking, resetTracking } from '@vue/reactivity'
+import { LifecycleHooks } from './enums'
export { onActivated, onDeactivated } from './components/KeepAlive'
validateCompatConfig
} from './compat/compatConfig'
import { SchedulerJob } from './scheduler'
+import { LifecycleHooks } from './enums'
export type Data = Record<string, unknown>
type LifecycleHook<TFn = Function> = TFn[] | null
-export const enum LifecycleHooks {
- BEFORE_CREATE = 'bc',
- CREATED = 'c',
- BEFORE_MOUNT = 'bm',
- MOUNTED = 'm',
- BEFORE_UPDATE = 'bu',
- UPDATED = 'u',
- BEFORE_UNMOUNT = 'bum',
- UNMOUNTED = 'um',
- DEACTIVATED = 'da',
- ACTIVATED = 'a',
- RENDER_TRIGGERED = 'rtg',
- RENDER_TRACKED = 'rtc',
- ERROR_CAPTURED = 'ec',
- SERVER_PREFETCH = 'sp'
-}
-
// use `E extends any` to force evaluating type to fix #2362
export type SetupContext<E = EmitsOptions> = E extends any
? {
--- /dev/null
+export const enum LifecycleHooks {
+ BEFORE_CREATE = 'bc',
+ CREATED = 'c',
+ BEFORE_MOUNT = 'bm',
+ MOUNTED = 'm',
+ BEFORE_UPDATE = 'bu',
+ UPDATED = 'u',
+ BEFORE_UNMOUNT = 'bum',
+ UNMOUNTED = 'um',
+ DEACTIVATED = 'da',
+ ACTIVATED = 'a',
+ RENDER_TRIGGERED = 'rtg',
+ RENDER_TRACKED = 'rtc',
+ ERROR_CAPTURED = 'ec',
+ SERVER_PREFETCH = 'sp'
+}
import { VNode } from './vnode'
-import { ComponentInternalInstance, LifecycleHooks } from './component'
+import { ComponentInternalInstance } from './component'
import { warn, pushWarningContext, popWarningContext } from './warning'
import { isPromise, isFunction } from '@vue/shared'
+import { LifecycleHooks } from './enums'
// contexts where user provided function may be executed, in addition to
// lifecycle hooks.
SCHEDULER
}
-export const ErrorTypeStrings: Record<number | string, string> = {
+export const ErrorTypeStrings: Record<LifecycleHooks | ErrorCodes, string> = {
[LifecycleHooks.SERVER_PREFETCH]: 'serverPrefetch hook',
[LifecycleHooks.BEFORE_CREATE]: 'beforeCreate hook',
[LifecycleHooks.CREATED]: 'created hook',
+import { vi } from 'vitest'
import { createApp, h } from '../src'
describe('createApp for dom', () => {
}
}
- const handler = jest.fn(msg => {
+ const handler = vi.fn(msg => {
expect(msg).toMatch(`Component is missing template or render function`)
})
+import { vi } from 'vitest'
import {
defineAsyncComponent,
defineComponent,
test('emit on connect', () => {
const e = new E()
- const spy = jest.fn()
+ const spy = vi.fn()
e.addEventListener('created', spy)
container.appendChild(e)
expect(spy).toHaveBeenCalled()
test('emit on interaction', () => {
container.innerHTML = `<my-el-emits></my-el-emits>`
const e = container.childNodes[0] as VueElement
- const spy = jest.fn()
+ const spy = vi.fn()
e.addEventListener('my-click', spy)
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
expect(spy).toHaveBeenCalledTimes(1)
test('case transform for camelCase event', () => {
container.innerHTML = `<my-el-emits></my-el-emits>`
const e = container.childNodes[0] as VueElement
- const spy1 = jest.fn()
+ const spy1 = vi.fn()
e.addEventListener('myEvent', spy1)
- const spy2 = jest.fn()
+ const spy2 = vi.fn()
// emitting myEvent, but listening for my-event. This happens when
// using the custom element in a Vue template
e.addEventListener('my-event', spy2)
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 = jest.fn()
+ 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')
customElements.define('my-async-el-props-emits', E)
container.innerHTML = `<my-async-el-props-emits id="my_async_el_props_emits"></my-async-el-props-emits>`
const e = container.childNodes[0] as VueElement
- const spy = jest.fn()
+ const spy = vi.fn()
e.addEventListener('my-click', spy)
await customElements.whenDefined('my-async-el-props-emits')
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
describe('async', () => {
test('should work', async () => {
- const loaderSpy = jest.fn()
+ const loaderSpy = vi.fn()
const E = defineCustomElement(
defineAsyncComponent(() => {
loaderSpy()
+import { vi } from 'vitest'
import { render, h } from '@vue/runtime-dom'
describe('customized built-in elements support', () => {
- let createElement: jest.SpyInstance
+ let createElement: vi.SpyInstance
afterEach(() => {
createElement.mockRestore()
})
test('should created element with is option', () => {
const root = document.createElement('div')
- createElement = jest.spyOn(document, 'createElement')
+ createElement = vi.spyOn(document, 'createElement')
render(h('button', { is: 'plastic-button' }), root)
expect(createElement.mock.calls[0]).toMatchObject([
'button',
+import { vi } from 'vitest'
import {
h,
render,
describe('vModel', () => {
it('should work with text input', async () => {
- const manualListener = jest.fn()
+ const manualListener = vi.fn()
const component = defineComponent({
data() {
return { value: null }
})
it('should work with multiple listeners', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const component = defineComponent({
data() {
return { value: null }
})
it('should work with updated listeners', async () => {
- const spy1 = jest.fn()
- const spy2 = jest.fn()
+ const spy1 = vi.fn()
+ const spy2 = vi.fn()
const toggle = ref(true)
const component = defineComponent({
+import { vi } from 'vitest'
import { patchEvent } from '../../src/modules/events'
import { withModifiers, withKeys } from '@vue/runtime-dom'
const parent = document.createElement('div')
const child = document.createElement('input')
parent.appendChild(child)
- const childNextValue = withModifiers(jest.fn(), ['prevent', 'stop'])
+ const childNextValue = withModifiers(vi.fn(), ['prevent', 'stop'])
patchEvent(child, 'onClick', null, childNextValue, null)
- const parentNextValue = jest.fn()
+ const parentNextValue = vi.fn()
patchEvent(parent, 'onClick', null, parentNextValue, null)
expect(triggerEvent(child, 'click').defaultPrevented).toBe(true)
expect(parentNextValue).not.toBeCalled()
const parent = document.createElement('div')
const child = document.createElement('input')
parent.appendChild(child)
- const fn = jest.fn()
+ const fn = vi.fn()
const handler = withModifiers(fn, ['self'])
patchEvent(parent, 'onClick', null, handler, null)
triggerEvent(child, 'click')
keyNames.forEach(keyName => {
const el = document.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
// <div @keyup[keyName].esc="test"/>
const nextValue = withKeys(withModifiers(fn, [keyName]), [
'esc',
test('it should support "exact" modifier', () => {
const el = document.createElement('div')
// Case 1: <div @keyup.exact="test"/>
- const fn1 = jest.fn()
+ const fn1 = vi.fn()
const next1 = withModifiers(fn1, ['exact'])
patchEvent(el, 'onKeyup', null, next1, null)
triggerEvent(el, 'keyup')
triggerEvent(el, 'keyup', e => (e.ctrlKey = true))
expect(fn1.mock.calls.length).toBe(1)
// Case 2: <div @keyup.ctrl.a.exact="test"/>
- const fn2 = jest.fn()
+ const fn2 = vi.fn()
const next2 = withKeys(withModifiers(fn2, ['ctrl', 'exact']), ['a'])
patchEvent(el, 'onKeyup', null, next2, null)
triggerEvent(el, 'keyup', e => (e.key = 'a'))
const buttonCodes = { left: 0, middle: 1, right: 2 }
buttons.forEach(button => {
const el = document.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
const handler = withModifiers(fn, [button])
patchEvent(el, 'onMousedown', null, handler, null)
buttons
it('should handle multiple arguments when using modifiers', () => {
const el = document.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
const handler = withModifiers(fn, ['ctrl'])
const event = triggerEvent(el, 'click', e => (e.ctrlKey = true))
handler(event, 'value', true)
+import { vi } from 'vitest'
import { patchProp } from '../src/patchProp'
const timeout = () => new Promise(r => setTimeout(r))
describe(`runtime-dom: events patching`, () => {
it('should assign event handler', async () => {
const el = document.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
patchProp(el, 'onClick', null, fn)
el.dispatchEvent(new Event('click'))
await timeout()
it('should update event handler', async () => {
const el = document.createElement('div')
- const prevFn = jest.fn()
- const nextFn = jest.fn()
+ const prevFn = vi.fn()
+ const nextFn = vi.fn()
patchProp(el, 'onClick', null, prevFn)
el.dispatchEvent(new Event('click'))
patchProp(el, 'onClick', prevFn, nextFn)
it('should support multiple event handlers', async () => {
const el = document.createElement('div')
- const fn1 = jest.fn()
- const fn2 = jest.fn()
+ const fn1 = vi.fn()
+ const fn2 = vi.fn()
patchProp(el, 'onClick', null, [fn1, fn2])
el.dispatchEvent(new Event('click'))
await timeout()
it('should unassign event handler', async () => {
const el = document.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
patchProp(el, 'onClick', null, fn)
patchProp(el, 'onClick', fn, null)
el.dispatchEvent(new Event('click'))
it('should support event option modifiers', async () => {
const el = document.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
patchProp(el, 'onClickOnceCapture', null, fn)
el.dispatchEvent(new Event('click'))
await timeout()
it('should unassign event handler with options', async () => {
const el = document.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
patchProp(el, 'onClickCapture', null, fn)
el.dispatchEvent(new Event('click'))
await timeout()
const el = document.createElement('div')
// string should be set as attribute
- const fn = ((window as any).__globalSpy = jest.fn())
+ const fn = ((window as any).__globalSpy = vi.fn())
patchProp(el, 'onclick', null, '__globalSpy(1)')
el.dispatchEvent(new Event('click'))
await timeout()
delete (window as any).__globalSpy
expect(fn).toHaveBeenCalledWith(1)
- const fn2 = jest.fn()
+ const fn2 = vi.fn()
patchProp(el, 'onclick', '__globalSpy(1)', fn2)
const event = new Event('click')
el.dispatchEvent(event)
it('should support stopImmediatePropagation on multiple listeners', async () => {
const el = document.createElement('div')
- const fn1 = jest.fn((e: Event) => {
+ const fn1 = vi.fn((e: Event) => {
e.stopImmediatePropagation()
})
- const fn2 = jest.fn()
+ const fn2 = vi.fn()
patchProp(el, 'onClick', null, [fn1, fn2])
el.dispatchEvent(new Event('click'))
await timeout()
const el2 = document.createElement('div')
// const event = new Event('click')
- const prevFn = jest.fn()
- const nextFn = jest.fn()
+ const prevFn = vi.fn()
+ const nextFn = vi.fn()
patchProp(el1, 'onClick', null, prevFn)
patchProp(el2, 'onClick', null, prevFn)
const child = document.createElement('div')
el.appendChild(child)
document.body.appendChild(el)
- const childFn = jest.fn()
- const parentFn = jest.fn()
+ const childFn = vi.fn()
+ const parentFn = vi.fn()
patchProp(child, 'onClick', null, () => {
childFn()
const testElement = document.createElement('test-element', {
is: 'test-element'
})
- const fn1 = jest.fn()
- const fn2 = jest.fn()
+ const fn1 = vi.fn()
+ const fn2 = vi.fn()
// in webComponents, @foo-bar will patch prop 'onFooBar'
// and @foobar will patch prop 'onFoobar'
+import { vi } from 'vitest'
import { patchProp } from '../src/patchProp'
import { render, h } from '../src'
})
test('innerHTML unmount prev children', () => {
- const fn = jest.fn()
+ const fn = vi.fn()
const comp = {
render: () => 'foo',
unmounted: fn
// #954
test('(svg) innerHTML unmount prev children', () => {
- const fn = jest.fn()
+ const fn = vi.fn()
const comp = {
render: () => 'foo',
unmounted: fn
})
test('textContent unmount prev children', () => {
- const fn = jest.fn()
+ const fn = vi.fn()
const comp = {
render: () => 'foo',
unmounted: fn
+import { vi } from 'vitest'
import { patchProp } from '../src/patchProp'
describe(`runtime-dom: style patching`, () => {
// #1309
it('should not patch same string style', () => {
const el = document.createElement('div')
- const fn = jest.fn()
+ const fn = vi.fn()
const value = (el.style.cssText = 'color:red;')
Object.defineProperty(el.style, 'cssText', {
get(): any {
* @jest-environment node
*/
+import { vi } from 'vitest'
import {
createApp,
h,
// #2763
test('error handling w/ async setup', async () => {
- const fn = jest.fn()
- const fn2 = jest.fn()
+ const fn = vi.fn()
+ const fn2 = vi.fn()
const asyncChildren = defineComponent({
async setup() {
})
test('onServerPrefetch are run in parallel', async () => {
- const first = jest.fn(() => Promise.resolve())
- const second = jest.fn(() => Promise.resolve())
+ const first = vi.fn(() => Promise.resolve())
+ const second = vi.fn(() => Promise.resolve())
let checkOther = [false, false]
let done = [false, false]
const app = createApp({
+import { vi } from 'vitest'
import { createSSRApp, defineComponent, h, computed, reactive } from 'vue'
import { renderToString } from '../src/renderToString'
}
}
- const getterSpy = jest.fn()
+ const getterSpy = vi.fn()
const App = defineComponent(async () => {
const msg = computed(() => {
* @jest-environment node
*/
+import { vi } from 'vitest'
import { createApp, h, Suspense } from 'vue'
import { renderToString } from '../src/renderToString'
test('reject', async () => {
const Comp = {
- errorCaptured: jest.fn(() => false),
+ errorCaptured: vi.fn(() => false),
render() {
return h(Suspense, null, {
default: h(RejectingAsync),
test('resolving component + rejecting component', async () => {
const Comp = {
- errorCaptured: jest.fn(() => false),
+ errorCaptured: vi.fn(() => false),
render() {
return h(Suspense, null, {
default: h('div', [h(ResolvingAsync), h(RejectingAsync)]),
test('failing suspense in passing suspense', async () => {
const Comp = {
- errorCaptured: jest.fn(() => false),
+ errorCaptured: vi.fn(() => false),
render() {
return h(Suspense, null, {
default: h('div', [
test('passing suspense in failing suspense', async () => {
const Comp = {
- errorCaptured: jest.fn(() => false),
+ errorCaptured: vi.fn(() => false),
render() {
return h(Suspense, null, {
default: h('div', [
+import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '@vue/runtime-core'
import { CompilerDeprecationTypes } from '../../compiler-core/src'
})
test('COMPILER_V_ON_NATIVE', () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const vm = new Vue({
template: `<child @click="spy" @click.native="spy" />`,
components: {
+import { vi } from 'vitest'
import Vue from '@vue/compat'
import { effect, isReactive } from '@vue/reactivity'
import { h, nextTick } from '@vue/runtime-core'
})
it('should not merge nested mixins created with Vue.extend', () => {
- const a = jest.fn()
- const b = jest.fn()
- const c = jest.fn()
- const d = jest.fn()
+ const a = vi.fn()
+ const b = vi.fn()
+ const c = vi.fn()
+ const d = vi.fn()
const A = Vue.extend({
created: a
})
const app1 = createApp({ render: () => h('div') })
const app2 = createApp({})
- const mixin = { created: jest.fn() }
+ const mixin = { created: vi.fn() }
app1.mixin(mixin)
app2.mixin(mixin)
+import { vi } from 'vitest'
import Vue from '@vue/compat'
import {
DeprecationTypes,
bar: [38, 87]
}
- const onFoo = jest.fn()
- const onBar = jest.fn()
+ const onFoo = vi.fn()
+ const onBar = vi.fn()
const el = document.createElement('div')
new Vue({
+import { vi } from 'vitest'
import Vue from '@vue/compat'
import { Slots } from '../../runtime-core/src/componentSlots'
import { Text } from '../../runtime-core/src/vnode'
// https://github.com/vuejs/vue/blob/dev/test/unit/features/instance/methods-events.spec.js
describe('INSTANCE_EVENT_EMITTER', () => {
let vm: LegacyPublicInstance
- let spy: jest.Mock
+ let spy: vi.Mock
beforeEach(() => {
vm = new Vue()
- spy = jest.fn()
+ spy = vi.fn()
})
it('$on', () => {
})
it('$off event + fn', () => {
- const spy2 = jest.fn()
+ const spy2 = vi.fn()
vm.$on('test', spy)
vm.$on('test', spy2)
vm.$off('test', spy)
describe('INSTANCE_EVENT_HOOKS', () => {
test('instance API', () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const vm = new Vue({ template: 'foo' })
vm.$on('hook:mounted', spy)
vm.$mount()
})
test('via template', () => {
- const spy = jest.fn()
+ const spy = vi.fn()
new Vue({
template: `<child @hook:mounted="spy"/>`,
methods: { spy },
+import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'
import {
})
test('WATCH_ARRAY', async () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const vm = new Vue({
data() {
return {
})
test('V_ON_KEYCODE_MODIFIER', () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const vm = new Vue({
template: `<input @keyup.1="spy">`,
methods: { spy }
test('CUSTOM_DIR', async () => {
const myDir = {
- bind: jest.fn(),
- inserted: jest.fn(),
- update: jest.fn(),
- componentUpdated: jest.fn(),
- unbind: jest.fn()
+ bind: vi.fn(),
+ inserted: vi.fn(),
+ update: vi.fn(),
+ componentUpdated: vi.fn(),
+ unbind: vi.fn()
} as any
const getCalls = () =>
+import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'
import {
})
test('beforeDestroy/destroyed', async () => {
- const beforeDestroy = jest.fn()
- const destroyed = jest.fn()
+ const beforeDestroy = vi.fn()
+ const destroyed = vi.fn()
const child = {
template: `foo`,
})
test('beforeDestroy/destroyed in Vue.extend components', async () => {
- const beforeDestroy = jest.fn()
- const destroyed = jest.fn()
+ const beforeDestroy = vi.fn()
+ const destroyed = vi.fn()
const child = Vue.extend({
template: `foo`,
+import { vi } from 'vitest'
import { E2E_TIMEOUT, setupPuppeteer } from './e2eUtils'
import path from 'path'
import { h, createApp, Transition, ref, nextTick } from 'vue'
test(
'transition events without appear',
async () => {
- const beforeLeaveSpy = jest.fn()
- const onLeaveSpy = jest.fn()
- const afterLeaveSpy = jest.fn()
- const beforeEnterSpy = jest.fn()
- const onEnterSpy = jest.fn()
- const afterEnterSpy = jest.fn()
+ const beforeLeaveSpy = vi.fn()
+ const onLeaveSpy = vi.fn()
+ const afterLeaveSpy = vi.fn()
+ const beforeEnterSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
await page().exposeFunction('onLeaveSpy', onLeaveSpy)
await page().exposeFunction('onEnterSpy', onEnterSpy)
test(
'events with arguments',
async () => {
- const beforeLeaveSpy = jest.fn()
- const onLeaveSpy = jest.fn()
- const afterLeaveSpy = jest.fn()
- const beforeEnterSpy = jest.fn()
- const onEnterSpy = jest.fn()
- const afterEnterSpy = jest.fn()
+ const beforeLeaveSpy = vi.fn()
+ const onLeaveSpy = vi.fn()
+ const afterLeaveSpy = vi.fn()
+ const beforeEnterSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
await page().exposeFunction('onLeaveSpy', onLeaveSpy)
await page().exposeFunction('onEnterSpy', onEnterSpy)
)
test('onEnterCancelled', async () => {
- const enterCancelledSpy = jest.fn()
+ const enterCancelledSpy = vi.fn()
await page().exposeFunction('enterCancelledSpy', enterCancelledSpy)
test(
'transition events with appear',
async () => {
- const onLeaveSpy = jest.fn()
- const onEnterSpy = jest.fn()
- const onAppearSpy = jest.fn()
- const beforeLeaveSpy = jest.fn()
- const beforeEnterSpy = jest.fn()
- const beforeAppearSpy = jest.fn()
- const afterLeaveSpy = jest.fn()
- const afterEnterSpy = jest.fn()
- const afterAppearSpy = jest.fn()
+ const onLeaveSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const onAppearSpy = vi.fn()
+ const beforeLeaveSpy = vi.fn()
+ const beforeEnterSpy = vi.fn()
+ const beforeAppearSpy = vi.fn()
+ const afterLeaveSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
+ const afterAppearSpy = vi.fn()
await page().exposeFunction('onLeaveSpy', onLeaveSpy)
await page().exposeFunction('onEnterSpy', onEnterSpy)
test(
'css: false',
async () => {
- const onBeforeEnterSpy = jest.fn()
- const onEnterSpy = jest.fn()
- const onAfterEnterSpy = jest.fn()
- const onBeforeLeaveSpy = jest.fn()
- const onLeaveSpy = jest.fn()
- const onAfterLeaveSpy = jest.fn()
+ const onBeforeEnterSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const onAfterEnterSpy = vi.fn()
+ const onBeforeLeaveSpy = vi.fn()
+ const onLeaveSpy = vi.fn()
+ const onAfterLeaveSpy = vi.fn()
await page().exposeFunction('onBeforeEnterSpy', onBeforeEnterSpy)
await page().exposeFunction('onEnterSpy', onEnterSpy)
test(
'async component transition inside Suspense',
async () => {
- const onLeaveSpy = jest.fn()
- const onEnterSpy = jest.fn()
+ const onLeaveSpy = vi.fn()
+ const onEnterSpy = vi.fn()
await page().exposeFunction('onLeaveSpy', onLeaveSpy)
await page().exposeFunction('onEnterSpy', onEnterSpy)
test(
'out-in mode with Suspense',
async () => {
- const onLeaveSpy = jest.fn()
- const onEnterSpy = jest.fn()
+ const onLeaveSpy = vi.fn()
+ const onEnterSpy = vi.fn()
await page().exposeFunction('onLeaveSpy', onLeaveSpy)
await page().exposeFunction('onEnterSpy', onEnterSpy)
test(
'transition events with v-show',
async () => {
- const beforeLeaveSpy = jest.fn()
- const onLeaveSpy = jest.fn()
- const afterLeaveSpy = jest.fn()
- const beforeEnterSpy = jest.fn()
- const onEnterSpy = jest.fn()
- const afterEnterSpy = jest.fn()
+ const beforeLeaveSpy = vi.fn()
+ const onLeaveSpy = vi.fn()
+ const afterLeaveSpy = vi.fn()
+ const beforeEnterSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
await page().exposeFunction('onLeaveSpy', onLeaveSpy)
await page().exposeFunction('onEnterSpy', onEnterSpy)
test(
'onLeaveCancelled (v-show only)',
async () => {
- const onLeaveCancelledSpy = jest.fn()
+ const onLeaveCancelledSpy = vi.fn()
await page().exposeFunction('onLeaveCancelledSpy', onLeaveCancelledSpy)
await page().evaluate(() => {
test(
'transition on appear with v-show',
async () => {
- const beforeEnterSpy = jest.fn()
- const onEnterSpy = jest.fn()
- const afterEnterSpy = jest.fn()
+ const beforeEnterSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
await page().exposeFunction('onEnterSpy', onEnterSpy)
await page().exposeFunction('beforeEnterSpy', beforeEnterSpy)
test(
'transition events should not call onEnter with v-show false',
async () => {
- const beforeEnterSpy = jest.fn()
- const onEnterSpy = jest.fn()
- const afterEnterSpy = jest.fn()
+ const beforeEnterSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
await page().exposeFunction('onEnterSpy', onEnterSpy)
await page().exposeFunction('beforeEnterSpy', beforeEnterSpy)
// #3227
test(`HOC w/ merged hooks`, async () => {
- const innerSpy = jest.fn()
- const outerSpy = jest.fn()
+ const innerSpy = vi.fn()
+ const outerSpy = vi.fn()
const MyTransition = {
render(this: any) {
+import { vi } from 'vitest'
import { E2E_TIMEOUT, setupPuppeteer } from './e2eUtils'
import path from 'path'
import { createApp, ref } from 'vue'
test(
'events',
async () => {
- const onLeaveSpy = jest.fn()
- const onEnterSpy = jest.fn()
- const onAppearSpy = jest.fn()
- const beforeLeaveSpy = jest.fn()
- const beforeEnterSpy = jest.fn()
- const beforeAppearSpy = jest.fn()
- const afterLeaveSpy = jest.fn()
- const afterEnterSpy = jest.fn()
- const afterAppearSpy = jest.fn()
+ const onLeaveSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const onAppearSpy = vi.fn()
+ const beforeLeaveSpy = vi.fn()
+ const beforeEnterSpy = vi.fn()
+ const beforeAppearSpy = vi.fn()
+ const afterLeaveSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
+ const afterAppearSpy = vi.fn()
await page().exposeFunction('onLeaveSpy', onLeaveSpy)
await page().exposeFunction('onEnterSpy', onEnterSpy)
+import { vi } from 'vitest'
import { createApp } from '../src'
// https://github.com/vuejs/docs/pull/1890
const container = document.createElement('div')
document.body.appendChild(container)
- const handler = jest.fn()
- const handler2 = jest.fn()
+ const handler = vi.fn()
+ const handler2 = vi.fn()
createApp({
template: `
<custom-event-casing
+import { vi } from 'vitest'
import { EMPTY_ARR } from '@vue/shared'
import { createApp, ref, nextTick, reactive } from '../src'
const one = {
name: 'one',
template: 'one',
- created: jest.fn(),
- mounted: jest.fn(),
- activated: jest.fn(),
- deactivated: jest.fn(),
- unmounted: jest.fn()
+ created: vi.fn(),
+ mounted: vi.fn(),
+ activated: vi.fn(),
+ deactivated: vi.fn(),
+ unmounted: vi.fn()
}
const toggle = ref(true)
it('should support selector of rootContainer', () => {
const container = document.createElement('div')
const origin = document.querySelector
- document.querySelector = jest.fn().mockReturnValue(container)
+ document.querySelector = vi.fn().mockReturnValue(container)
const App = {
template: `{{ count }}`,
it('should warn when container is not found', () => {
const origin = document.querySelector
- document.querySelector = jest.fn().mockReturnValue(null)
+ document.querySelector = vi.fn().mockReturnValue(null)
const App = {
template: `{{ count }}`,
data() {
const target = document.createElement('div')
const count = ref(0)
const origin = document.querySelector
- document.querySelector = jest.fn().mockReturnValue(target)
+ document.querySelector = vi.fn().mockReturnValue(target)
const App = {
template: `
tslib: ^2.4.0
typescript: ^4.8.0
vite: ^4.0.4
+ vitest: ^0.28.2
vue: workspace:*
devDependencies:
'@babel/types': 7.16.0
tslib: 2.4.0
typescript: 4.8.2
vite: 4.0.4_suj7upvbbzn7525gsozjyvtnxy
+ vitest: 0.28.2_terser@5.15.1
vue: link:packages/vue
packages/compiler-core:
'@babel/types': 7.16.0
dev: true
+ /@types/chai-subset/1.3.3:
+ resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==}
+ dependencies:
+ '@types/chai': 4.3.4
+ dev: true
+
+ /@types/chai/4.3.4:
+ resolution: {integrity: sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw==}
+ dev: true
+
/@types/estree/0.0.48:
resolution: {integrity: sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==}
dev: true
vue: link:packages/vue
dev: true
+ /@vitest/expect/0.28.2:
+ resolution: {integrity: sha512-syEAK7I24/aGR2lXma98WNnvMwAJ+fMx32yPcj8eLdCEWjZI3SH8ozMaKQMy65B/xZCZAl6MXmfjtJb2CpWPMg==}
+ dependencies:
+ '@vitest/spy': 0.28.2
+ '@vitest/utils': 0.28.2
+ chai: 4.3.7
+ dev: true
+
+ /@vitest/runner/0.28.2:
+ resolution: {integrity: sha512-BJ9CtfPwWM8uc5p7Ty0OprwApyh8RIaSK7QeQPhwfDYA59AAE009OytqA3aX0yj1Qy5+k/mYFJS8RJZgsueSGA==}
+ dependencies:
+ '@vitest/utils': 0.28.2
+ p-limit: 4.0.0
+ pathe: 1.1.0
+ dev: true
+
+ /@vitest/spy/0.28.2:
+ resolution: {integrity: sha512-KlLzTzi5E6tHcI12VT+brlY1Pdi7sUzLf9+YXgh80+CfLu9DqPZi38doBBAUhqEnW/emoLCMinPMMoJlNAQZXA==}
+ dependencies:
+ tinyspy: 1.0.2
+ dev: true
+
+ /@vitest/utils/0.28.2:
+ resolution: {integrity: sha512-wcVTNnVdr22IGxZHDgiXrxWYcXsNg0iX2iBuOH3tVs9eme6fXJ0wxjn0/gCpp0TofQSoUwo3tX8LNACFVseDuA==}
+ dependencies:
+ cli-truncate: 3.1.0
+ diff: 5.1.0
+ loupe: 2.3.6
+ picocolors: 1.0.0
+ pretty-format: 27.5.1
+ dev: true
+
/@vue/consolidate/0.17.3:
resolution: {integrity: sha512-nl0SWcTMzaaTnJ5G6V8VlMDA1CVVrNnaQKF1aBZU3kXtjgU9jtHMsEAsgjoRUx+T0EVJk9TgbmxGhK3pOk22zw==}
engines: {node: '>= 0.12.0'}
engines: {node: '>=8'}
dev: true
+ /ansi-regex/6.0.1:
+ resolution: {integrity: sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==}
+ engines: {node: '>=12'}
+ dev: true
+
/ansi-styles/3.2.1:
resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==}
engines: {node: '>=4'}
engines: {node: '>=10'}
dev: true
+ /ansi-styles/6.2.1:
+ resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==}
+ engines: {node: '>=12'}
+ dev: true
+
/anymatch/3.1.2:
resolution: {integrity: sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==}
engines: {node: '>= 8'}
resolution: {integrity: sha512-TaTivMB6pYI1kXwrFlEhLeGfOqoDNdTxjCdwRfFFkEA30Eu+k48W34nlok2EYWJfFFzqaEmichdNM7th6M5HNw==}
dev: true
+ /assertion-error/1.1.0:
+ resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==}
+ dev: true
+
/astral-regex/2.0.0:
resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==}
engines: {node: '>=8'}
engines: {node: '>= 0.8'}
dev: true
+ /cac/6.7.14:
+ resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==}
+ engines: {node: '>=8'}
+ dev: true
+
/call-bind/1.0.2:
resolution: {integrity: sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==}
dependencies:
resolution: {integrity: sha512-zaEMRH6xg8ESMi2eQ3R4eZ5qw/hJiVsO/HlLwniIwErij0JDr9P+8V4dtx1l+kLq6j3yy8l8W4fst1lBnat5wQ==}
dev: true
+ /chai/4.3.7:
+ resolution: {integrity: sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A==}
+ engines: {node: '>=4'}
+ dependencies:
+ assertion-error: 1.1.0
+ check-error: 1.0.2
+ deep-eql: 4.1.3
+ get-func-name: 2.0.0
+ loupe: 2.3.6
+ pathval: 1.1.1
+ type-detect: 4.0.8
+ dev: true
+
/chalk/2.4.1:
resolution: {integrity: sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==}
engines: {node: '>=4'}
is-regex: 1.1.4
dev: true
+ /check-error/1.0.2:
+ resolution: {integrity: sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==}
+ dev: true
+
/chokidar/3.5.2:
resolution: {integrity: sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==}
engines: {node: '>= 8.10.0'}
string-width: 4.2.3
dev: true
+ /cli-truncate/3.1.0:
+ resolution: {integrity: sha512-wfOBkjXteqSnI59oPcJkcPl/ZmwvMMOj340qUIY1SKZCv0B9Cf4D4fAucRkIKQmsIuYK3x1rrgU7MeGRruiuiA==}
+ engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
+ dependencies:
+ slice-ansi: 5.0.0
+ string-width: 5.1.2
+ dev: true
+
/clipboardy/2.3.0:
resolution: {integrity: sha512-mKhiIL2DrQIsuXMgBgnfEHOZOryC7kY7YO//TN6c63wlEm3NG5tz+YgY5rVi29KCmq/QQjKYvM7a19+MDOTHOQ==}
engines: {node: '>=8'}
resolution: {integrity: sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw=}
dev: true
+ /deep-eql/4.1.3:
+ resolution: {integrity: sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==}
+ engines: {node: '>=6'}
+ dependencies:
+ type-detect: 4.0.8
+ dev: true
+
/deep-extend/0.6.0:
resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==}
engines: {node: '>=4.0.0'}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dev: true
+ /diff/5.1.0:
+ resolution: {integrity: sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==}
+ engines: {node: '>=0.3.1'}
+ dev: true
+
/diffie-hellman/5.0.3:
resolution: {integrity: sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==}
dependencies:
is-obj: 2.0.0
dev: true
+ /eastasianwidth/0.2.0:
+ resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
+ dev: true
+
/electron-to-chromium/1.4.16:
resolution: {integrity: sha512-BQb7FgYwnu6haWLU63/CdVW+9xhmHls3RCQUFiV4lvw3wimEHTVcUk2hkuZo76QhR8nnDdfZE7evJIZqijwPdA==}
dev: true
resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
dev: true
+ /emoji-regex/9.2.2:
+ resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==}
+ dev: true
+
/emojis-list/3.0.0:
resolution: {integrity: sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==}
engines: {node: '>= 4'}
engines: {node: 6.* || 8.* || >= 10.*}
dev: true
+ /get-func-name/2.0.0:
+ resolution: {integrity: sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==}
+ dev: true
+
/get-intrinsic/1.1.1:
resolution: {integrity: sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==}
dependencies:
engines: {node: '>=8'}
dev: true
+ /is-fullwidth-code-point/4.0.0:
+ resolution: {integrity: sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==}
+ engines: {node: '>=12'}
+ dev: true
+
/is-generator-fn/2.1.0:
resolution: {integrity: sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ==}
engines: {node: '>=6'}
hasBin: true
dev: true
+ /jsonc-parser/3.2.0:
+ resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==}
+ dev: true
+
/jsonfile/4.0.0:
resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==}
optionalDependencies:
json5: 1.0.1
dev: true
+ /local-pkg/0.4.3:
+ resolution: {integrity: sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==}
+ engines: {node: '>=14'}
+ dev: true
+
/locate-path/2.0.0:
resolution: {integrity: sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==}
engines: {node: '>=4'}
wrap-ansi: 6.2.0
dev: true
+ /loupe/2.3.6:
+ resolution: {integrity: sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==}
+ dependencies:
+ get-func-name: 2.0.0
+ dev: true
+
/lru-cache/4.1.5:
resolution: {integrity: sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==}
dependencies:
resolution: {integrity: sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==}
dev: true
+ /mlly/1.1.0:
+ resolution: {integrity: sha512-cwzBrBfwGC1gYJyfcy8TcZU1f+dbH/T+TuOhtYP2wLv/Fb51/uV7HJQfBPtEupZ2ORLRU1EKFS/QfS3eo9+kBQ==}
+ dependencies:
+ acorn: 8.8.1
+ pathe: 1.1.0
+ pkg-types: 1.0.1
+ ufo: 1.0.1
+ dev: true
+
/modify-values/1.0.1:
resolution: {integrity: sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==}
engines: {node: '>=0.10.0'}
yocto-queue: 0.1.0
dev: true
+ /p-limit/4.0.0:
+ resolution: {integrity: sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ==}
+ engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
+ dependencies:
+ yocto-queue: 1.0.0
+ dev: true
+
/p-locate/2.0.0:
resolution: {integrity: sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==}
engines: {node: '>=4'}
engines: {node: '>=8'}
dev: true
+ /pathe/1.1.0:
+ resolution: {integrity: sha512-ODbEPR0KKHqECXW1GoxdDb+AZvULmXjVPy4rt+pGo2+TnjJTIPJQSVS6N63n8T2Ip+syHhbn52OewKicV0373w==}
+ dev: true
+
+ /pathval/1.1.1:
+ resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==}
+ dev: true
+
/pbkdf2/3.1.2:
resolution: {integrity: sha512-iuh7L6jA7JEGu2WxDwtQP1ddOpaJNC4KlDEFfdQajSGgGPNi4OyDc2R7QnbY2bR9QjBVGwgvTdNJZoE7RaxUMA==}
engines: {node: '>=0.12'}
find-up: 4.1.0
dev: true
+ /pkg-types/1.0.1:
+ resolution: {integrity: sha512-jHv9HB+Ho7dj6ItwppRDDl0iZRYBD0jsakHXtFgoLr+cHSF6xC+QL54sJmWxyGxOLYSHm0afhXhXcQDQqH9z8g==}
+ dependencies:
+ jsonc-parser: 3.2.0
+ mlly: 1.1.0
+ pathe: 1.1.0
+ dev: true
+
/please-upgrade-node/3.2.0:
resolution: {integrity: sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==}
dependencies:
hasBin: true
dev: true
+ /pretty-format/27.5.1:
+ resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==}
+ engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
+ dependencies:
+ ansi-regex: 5.0.1
+ ansi-styles: 5.2.0
+ react-is: 17.0.2
+ dev: true
+
/pretty-format/29.3.1:
resolution: {integrity: sha512-FyLnmb1cYJV8biEIiRyzRFvs2lry7PPIvOqKVe1GCUEYg4YGmlx1qG9EJNMxArYm7piII4qb8UV1Pncq5dxmcg==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
strip-json-comments: 2.0.1
dev: true
+ /react-is/17.0.2:
+ resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==}
+ dev: true
+
/react-is/18.2.0:
resolution: {integrity: sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==}
dev: true
object-inspect: 1.11.1
dev: true
+ /siginfo/2.0.0:
+ resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==}
+ dev: true
+
/signal-exit/3.0.6:
resolution: {integrity: sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==}
dev: true
is-fullwidth-code-point: 3.0.0
dev: true
+ /slice-ansi/5.0.0:
+ resolution: {integrity: sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ==}
+ engines: {node: '>=12'}
+ dependencies:
+ ansi-styles: 6.2.1
+ is-fullwidth-code-point: 4.0.0
+ dev: true
+
/source-map-js/1.0.1:
resolution: {integrity: sha512-4+TN2b3tqOCd/kaGRJ/sTYA0tR0mdXx26ipdolxcwtJVqEnqNYvlCAt1q3ypy4QMlYus+Zh34RNtYLoq2oQ4IA==}
engines: {node: '>=0.10.0'}
escape-string-regexp: 2.0.0
dev: true
+ /stackback/0.0.2:
+ resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==}
+ dev: true
+
+ /std-env/3.3.1:
+ resolution: {integrity: sha512-3H20QlwQsSm2OvAxWIYhs+j01MzzqwMwGiiO1NQaJYZgJZFPuAbf95/DiKRBSTYIJ2FeGUc+B/6mPGcWP9dO3Q==}
+ dev: true
+
/string-argv/0.3.1:
resolution: {integrity: sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==}
engines: {node: '>=0.6.19'}
strip-ansi: 6.0.1
dev: true
+ /string-width/5.1.2:
+ resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==}
+ engines: {node: '>=12'}
+ dependencies:
+ eastasianwidth: 0.2.0
+ emoji-regex: 9.2.2
+ strip-ansi: 7.0.1
+ dev: true
+
/string.prototype.padend/3.1.3:
resolution: {integrity: sha512-jNIIeokznm8SD/TZISQsZKYu7RJyheFNt84DUPrh482GC8RVp2MKqm2O5oBRdGxbDQoXrhhWtPIWQOiy20svUg==}
engines: {node: '>= 0.4'}
ansi-regex: 5.0.1
dev: true
+ /strip-ansi/7.0.1:
+ resolution: {integrity: sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw==}
+ engines: {node: '>=12'}
+ dependencies:
+ ansi-regex: 6.0.1
+ dev: true
+
/strip-bom/3.0.0:
resolution: {integrity: sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=}
engines: {node: '>=4'}
engines: {node: '>=8'}
dev: true
+ /strip-literal/1.0.0:
+ resolution: {integrity: sha512-5o4LsH1lzBzO9UFH63AJ2ad2/S2AVx6NtjOcaz+VTT2h1RiRvbipW72z8M/lxEhcPHDBQwpDrnTF7sXy/7OwCQ==}
+ dependencies:
+ acorn: 8.8.1
+ dev: true
+
/supports-color/5.5.0:
resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==}
engines: {node: '>=4'}
resolution: {integrity: sha512-qsdtZH+vMoCARQtyod4imc2nIJwg9Cc7lPRrw9CzF8ZKR0khdr8+2nX80PBhET3tcyTtJDxAffGh2rXH4tyU8A==}
dev: true
+ /tinybench/2.3.1:
+ resolution: {integrity: sha512-hGYWYBMPr7p4g5IarQE7XhlyWveh1EKhy4wUBS1LrHXCKYgvz+4/jCqgmJqZxxldesn05vccrtME2RLLZNW7iA==}
+ dev: true
+
+ /tinypool/0.3.0:
+ resolution: {integrity: sha512-NX5KeqHOBZU6Bc0xj9Vr5Szbb1j8tUHIeD18s41aDJaPeC5QTdEhK0SpdpUrZlj2nv5cctNcSjaKNanXlfcVEQ==}
+ engines: {node: '>=14.0.0'}
+ dev: true
+
+ /tinyspy/1.0.2:
+ resolution: {integrity: sha512-bSGlgwLBYf7PnUsQ6WOc6SJ3pGOcd+d8AA6EUnLDDM0kWEstC1JIlSZA3UNliDXhd9ABoS7hiRBDCu+XP/sf1Q==}
+ engines: {node: '>=14.0.0'}
+ dev: true
+
/tmpl/1.0.5:
resolution: {integrity: sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==}
dev: true
hasBin: true
dev: true
+ /ufo/1.0.1:
+ resolution: {integrity: sha512-boAm74ubXHY7KJQZLlXrtMz52qFvpsbOxDcZOnw/Wf+LS4Mmyu7JxmzD4tDLtUQtmZECypJ0FrCz4QIe6dvKRA==}
+ dev: true
+
/uglify-js/3.17.4:
resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==}
engines: {node: '>=0.8.0'}
engines: {node: '>= 0.8'}
dev: true
+ /vite-node/0.28.2_cuughdtwg7b3rwlnomrzdiszke:
+ resolution: {integrity: sha512-zyiJ3DLs9zXign4P2MD4PQk+7rdT+JkHukgmmS0KuImbCQ7WnCdea5imQVeT6OtUsBwsLztJxQODUsinVr91tg==}
+ engines: {node: '>=v14.16.0'}
+ hasBin: true
+ dependencies:
+ cac: 6.7.14
+ debug: 4.3.4
+ mlly: 1.1.0
+ pathe: 1.1.0
+ picocolors: 1.0.0
+ source-map: 0.6.1
+ source-map-support: 0.5.21
+ vite: 4.0.4_cuughdtwg7b3rwlnomrzdiszke
+ transitivePeerDependencies:
+ - '@types/node'
+ - less
+ - sass
+ - stylus
+ - sugarss
+ - supports-color
+ - terser
+ dev: true
+
/vite/4.0.4:
resolution: {integrity: sha512-xevPU7M8FU0i/80DMR+YhgrzR5KS2ORy1B4xcX/cXLsvnUWvfHuqMmVU6N0YiJ4JWGRJJsLCgjEzKjG9/GKoSw==}
engines: {node: ^14.18.0 || >=16.0.0}
fsevents: 2.3.2
dev: true
+ /vite/4.0.4_cuughdtwg7b3rwlnomrzdiszke:
+ resolution: {integrity: sha512-xevPU7M8FU0i/80DMR+YhgrzR5KS2ORy1B4xcX/cXLsvnUWvfHuqMmVU6N0YiJ4JWGRJJsLCgjEzKjG9/GKoSw==}
+ engines: {node: ^14.18.0 || >=16.0.0}
+ hasBin: true
+ peerDependencies:
+ '@types/node': '>= 14'
+ less: '*'
+ sass: '*'
+ stylus: '*'
+ sugarss: '*'
+ terser: ^5.4.0
+ peerDependenciesMeta:
+ '@types/node':
+ optional: true
+ less:
+ optional: true
+ sass:
+ optional: true
+ stylus:
+ optional: true
+ sugarss:
+ optional: true
+ terser:
+ optional: true
+ dependencies:
+ '@types/node': 16.18.2
+ esbuild: 0.16.17
+ postcss: 8.4.21
+ resolve: 1.22.1
+ rollup: 3.10.0
+ terser: 5.15.1
+ optionalDependencies:
+ fsevents: 2.3.2
+ dev: true
+
/vite/4.0.4_suj7upvbbzn7525gsozjyvtnxy:
resolution: {integrity: sha512-xevPU7M8FU0i/80DMR+YhgrzR5KS2ORy1B4xcX/cXLsvnUWvfHuqMmVU6N0YiJ4JWGRJJsLCgjEzKjG9/GKoSw==}
engines: {node: ^14.18.0 || >=16.0.0}
fsevents: 2.3.2
dev: true
+ /vitest/0.28.2_terser@5.15.1:
+ resolution: {integrity: sha512-HJBlRla4Mng0OiZ8aWunCecJ6BzLDA4yuzuxiBuBU2MXjGB6I4zT7QgIBL/UrwGKlNxLwaDC5P/4OpeuTlW8yQ==}
+ engines: {node: '>=v14.16.0'}
+ hasBin: true
+ peerDependencies:
+ '@edge-runtime/vm': '*'
+ '@vitest/browser': '*'
+ '@vitest/ui': '*'
+ happy-dom: '*'
+ jsdom: '*'
+ peerDependenciesMeta:
+ '@edge-runtime/vm':
+ optional: true
+ '@vitest/browser':
+ optional: true
+ '@vitest/ui':
+ optional: true
+ happy-dom:
+ optional: true
+ jsdom:
+ optional: true
+ dependencies:
+ '@types/chai': 4.3.4
+ '@types/chai-subset': 1.3.3
+ '@types/node': 16.18.2
+ '@vitest/expect': 0.28.2
+ '@vitest/runner': 0.28.2
+ '@vitest/spy': 0.28.2
+ '@vitest/utils': 0.28.2
+ acorn: 8.8.1
+ acorn-walk: 8.2.0
+ cac: 6.7.14
+ chai: 4.3.7
+ debug: 4.3.4
+ local-pkg: 0.4.3
+ pathe: 1.1.0
+ picocolors: 1.0.0
+ source-map: 0.6.1
+ std-env: 3.3.1
+ strip-literal: 1.0.0
+ tinybench: 2.3.1
+ tinypool: 0.3.0
+ tinyspy: 1.0.2
+ vite: 4.0.4_cuughdtwg7b3rwlnomrzdiszke
+ vite-node: 0.28.2_cuughdtwg7b3rwlnomrzdiszke
+ why-is-node-running: 2.2.2
+ transitivePeerDependencies:
+ - less
+ - sass
+ - stylus
+ - sugarss
+ - supports-color
+ - terser
+ dev: true
+
/vlq/0.2.3:
resolution: {integrity: sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==}
dev: true
isexe: 2.0.0
dev: true
+ /why-is-node-running/2.2.2:
+ resolution: {integrity: sha512-6tSwToZxTOcotxHeA+qGCq1mVzKR3CwcJGmVcY+QE8SHy6TnpFnh8PAvPNHYr7EcuVeG0QSMxtYCuO1ta/G/oA==}
+ engines: {node: '>=8'}
+ hasBin: true
+ dependencies:
+ siginfo: 2.0.0
+ stackback: 0.0.2
+ dev: true
+
/widest-line/2.0.1:
resolution: {integrity: sha512-Ba5m9/Fa4Xt9eb2ELXt77JxVDV8w7qQrH0zS/TWSJdLyAwQjWoOzpzj5lwVftDz6n/EOu3tNACS84v509qwnJA==}
engines: {node: '>=4'}
engines: {node: '>=10'}
dev: true
+ /yocto-queue/1.0.0:
+ resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==}
+ engines: {node: '>=12.20'}
+ dev: true
+
/z-schema/5.0.4:
resolution: {integrity: sha512-gm/lx3hDzJNcLwseIeQVm1UcwhWIKpSB4NqH89pTBtFns4k/HDHudsICtvG05Bvw/Mv3jMyk700y5dadueLHdA==}
engines: {node: '>=8.0.0'}
--- /dev/null
+import { vi } from 'vitest'
+
+expect.extend({
+ toHaveBeenWarned(received: string) {
+ asserted.add(received)
+ const passed = warn.mock.calls.some(args => args[0].includes(received))
+ if (passed) {
+ return {
+ pass: true,
+ message: () => `expected "${received}" not to have been warned.`
+ }
+ } else {
+ const msgs = warn.mock.calls.map(args => args[0]).join('\n - ')
+ return {
+ pass: false,
+ message: () =>
+ `expected "${received}" to have been warned` +
+ (msgs.length
+ ? `.\n\nActual messages:\n\n - ${msgs}`
+ : ` but no warning was recorded.`)
+ }
+ }
+ },
+
+ toHaveBeenWarnedLast(received: string) {
+ asserted.add(received)
+ const passed =
+ warn.mock.calls[warn.mock.calls.length - 1][0].includes(received)
+ if (passed) {
+ return {
+ pass: true,
+ message: () => `expected "${received}" not to have been warned last.`
+ }
+ } else {
+ const msgs = warn.mock.calls.map(args => args[0]).join('\n - ')
+ return {
+ pass: false,
+ message: () =>
+ `expected "${received}" to have been warned last.\n\nActual messages:\n\n - ${msgs}`
+ }
+ }
+ },
+
+ toHaveBeenWarnedTimes(received: string, n: number) {
+ asserted.add(received)
+ let found = 0
+ warn.mock.calls.forEach(args => {
+ if (args[0].includes(received)) {
+ found++
+ }
+ })
+
+ if (found === n) {
+ return {
+ pass: true,
+ message: () => `expected "${received}" to have been warned ${n} times.`
+ }
+ } else {
+ return {
+ pass: false,
+ message: () =>
+ `expected "${received}" to have been warned ${n} times but got ${found}.`
+ }
+ }
+ }
+})
+
+let warn
+const asserted: Set<string> = new Set()
+
+beforeEach(() => {
+ asserted.clear()
+ warn = vi.spyOn(console, 'warn')
+ warn.mockImplementation(() => {})
+})
+
+afterEach(() => {
+ const assertedArray = Array.from(asserted)
+ const nonAssertedWarnings = warn.mock.calls
+ .map(args => args[0])
+ .filter(received => {
+ return !assertedArray.some(assertedMsg => {
+ return received.includes(assertedMsg)
+ })
+ })
+ warn.mockRestore()
+ if (nonAssertedWarnings.length) {
+ throw new Error(
+ `test case threw unexpected warnings:\n - ${nonAssertedWarnings.join(
+ '\n - '
+ )}`
+ )
+ }
+})
--- /dev/null
+import { defineConfig } from 'vitest/config'
+import path from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { readdirSync } from 'node:fs'
+
+const resolve = p =>
+ path.resolve(fileURLToPath(import.meta.url), `../packages/${p}/src`)
+const dirs = readdirSync(new URL('./packages', import.meta.url))
+const alias = {}
+for (const dir of dirs) {
+ alias[`@vue/${dir}`] = resolve(dir)
+}
+
+export default defineConfig({
+ define: {
+ __DEV__: true,
+ __TEST__: true,
+ __VERSION__: '"test"',
+ __BROWSER__: false,
+ __GLOBAL__: false,
+ __ESM_BUNDLER__: true,
+ __ESM_BROWSER__: false,
+ __NODE_JS__: true,
+ __SSR__: true,
+ __FEATURE_OPTIONS_API__: true,
+ __FEATURE_SUSPENSE__: true,
+ __FEATURE_PROD_DEVTOOLS__: false,
+ __COMPAT__: true
+ },
+ resolve: {
+ alias: {
+ ...alias,
+ vue: resolve('vue'),
+ 'vue/compiler-sfc': resolve('compiler-sfc'),
+ 'vue/server-renderer': resolve('server-renderer'),
+ '@vue/compat': resolve('vue-compat')
+ }
+ },
+ test: {
+ globals: true,
+ setupFiles: 'scripts/setupVitest.ts'
+ }
+})