wip(vitest-migration): reactivity tests passing

This commit is contained in:
Evan You 2023-01-26 15:25:55 +08:00
parent ab45f6f8a2
commit 8867bb259a
83 changed files with 1122 additions and 545 deletions

View File

@ -102,6 +102,7 @@
"tslib": "^2.4.0",
"typescript": "^4.8.0",
"vite": "^4.0.4",
"vitest": "^0.28.2",
"vue": "workspace:*"
}
}

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { ParserOptions } from '../src/options'
import { baseParse, TextModes } from '../src/parse'
import { ErrorCodes } from '../src/errors'
@ -31,7 +32,7 @@ describe('compiler: parse', () => {
})
test('simple text with invalid end tag', () => {
const onError = jest.fn()
const onError = vi.fn()
const ast = baseParse('some text</div>', {
onError
})
@ -1844,7 +1845,7 @@ describe('compiler: parse', () => {
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
})
@ -3034,7 +3035,7 @@ foo
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

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { baseParse } from '../src/parse'
import { transform, NodeTransform } from '../src/transform'
import {
@ -88,7 +89,7 @@ describe('compiler: transform', () => {
)
}
}
const spy = jest.fn(plugin)
const spy = vi.fn(plugin)
transform(ast, {
nodeTransforms: [spy]
})
@ -113,7 +114,7 @@ describe('compiler: transform', () => {
context.removeNode()
}
}
const spy = jest.fn(plugin)
const spy = vi.fn(plugin)
transform(ast, {
nodeTransforms: [spy]
})
@ -141,7 +142,7 @@ describe('compiler: transform', () => {
context.removeNode(context.parent!.children[0])
}
}
const spy = jest.fn(plugin)
const spy = vi.fn(plugin)
transform(ast, {
nodeTransforms: [spy]
})
@ -168,7 +169,7 @@ describe('compiler: transform', () => {
context.removeNode(context.parent!.children[1])
}
}
const spy = jest.fn(plugin)
const spy = vi.fn(plugin)
transform(ast, {
nodeTransforms: [spy]
})
@ -209,7 +210,7 @@ describe('compiler: transform', () => {
createCompilerError(ErrorCodes.X_INVALID_END_TAG, node.loc)
)
}
const spy = jest.fn()
const spy = vi.fn()
transform(ast, {
nodeTransforms: [plugin],
onError: spy

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
CompilerOptions,
baseParse as parse,
@ -531,7 +532,7 @@ describe('compiler: element transform', () => {
})
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([
{

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
baseParse as parse,
transform,
@ -395,7 +396,7 @@ describe('compiler: expression 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`

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
CompilerOptions,
baseParse as parse,
@ -369,7 +370,7 @@ describe('compiler: transform <slot> outlets', () => {
})
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')

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
baseParse as parse,
transform,
@ -99,7 +100,7 @@ describe('compiler: transform v-bind', () => {
})
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({

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { baseParse as parse } from '../../src/parse'
import { transform } from '../../src/transform'
import { transformIf } from '../../src/transforms/vIf'
@ -206,7 +207,7 @@ describe('compiler: v-for', () => {
describe('errors', () => {
test('missing expression', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithForTransform('<span v-for />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@ -218,7 +219,7 @@ describe('compiler: v-for', () => {
})
test('empty expression', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithForTransform('<span v-for="" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@ -230,7 +231,7 @@ describe('compiler: v-for', () => {
})
test('invalid expression', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithForTransform('<span v-for="items" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@ -242,7 +243,7 @@ describe('compiler: v-for', () => {
})
test('missing source', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithForTransform('<span v-for="item in" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@ -254,7 +255,7 @@ describe('compiler: v-for', () => {
})
test('missing value', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithForTransform('<span v-for="in items" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@ -266,7 +267,7 @@ describe('compiler: v-for', () => {
})
test('<template v-for> key placement', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithForTransform(
`
<template v-for="item in items">

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { baseParse as parse } from '../../src/parse'
import { transform } from '../../src/transform'
import { transformIf } from '../../src/transforms/vIf'
@ -213,7 +214,7 @@ describe('compiler: v-if', () => {
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([
@ -249,7 +250,7 @@ describe('compiler: v-if', () => {
})
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
@ -302,7 +303,7 @@ describe('compiler: v-if', () => {
})
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" />`,

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
baseParse as parse,
transform,
@ -506,7 +507,7 @@ describe('compiler: transform v-model', () => {
describe('errors', () => {
test('missing expression', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithVModel('<span v-model />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@ -518,7 +519,7 @@ describe('compiler: transform v-model', () => {
})
test('empty expression', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithVModel('<span v-model="" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@ -530,7 +531,7 @@ describe('compiler: transform v-model', () => {
})
test('mal-formed expression', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithVModel('<span v-model="a + b" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@ -542,14 +543,14 @@ describe('compiler: transform v-model', () => {
})
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
@ -564,7 +565,7 @@ describe('compiler: transform v-model', () => {
})
test('used on props', () => {
const onError = jest.fn()
const onError = vi.fn()
parseWithVModel('<div v-model="p" />', {
onError,
bindingMetadata: {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
baseParse as parse,
CompilerOptions,
@ -398,7 +399,7 @@ describe('compiler: transform v-on', () => {
})
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,
@ -416,7 +417,7 @@ describe('compiler: transform v-on', () => {
})
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()
})

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
CompilerOptions,
baseParse as parse,
@ -843,7 +844,7 @@ describe('compiler: transform component slots', () => {
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')
@ -866,7 +867,7 @@ describe('compiler: transform component slots', () => {
})
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')
@ -889,7 +890,7 @@ describe('compiler: transform component slots', () => {
})
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')
@ -912,7 +913,7 @@ describe('compiler: transform component slots', () => {
})
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')

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { compile } from '../../src'
describe('Transition multi children warnings', () => {
@ -6,7 +7,7 @@ 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,

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
baseParse as parse,
transform,
@ -40,7 +41,7 @@ describe('compiler: v-html 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
})
@ -59,7 +60,7 @@ describe('compiler: v-html transform', () => {
})
it('should raise error if has no expression', () => {
const onError = jest.fn()
const onError = vi.fn()
transformWithVHtml(`<div v-html></div>`, {
onError
})

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
baseParse as parse,
transform,
@ -92,7 +93,7 @@ describe('compiler: transform v-model', () => {
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)
@ -104,7 +105,7 @@ describe('compiler: transform v-model', () => {
})
test('invalid element', () => {
const onError = jest.fn()
const onError = vi.fn()
transformWithModel('<span v-model="model" />', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@ -116,7 +117,7 @@ describe('compiler: transform v-model', () => {
})
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-')
@ -127,7 +128,7 @@ describe('compiler: transform v-model', () => {
})
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
})

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
baseParse as parse,
transform,
@ -28,7 +29,7 @@ describe('compiler: v-show 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)

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
baseParse as parse,
transform,
@ -42,7 +43,7 @@ describe('compiler: v-text 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
})
@ -63,7 +64,7 @@ describe('compiler: v-text transform', () => {
})
it('should raise error if has no expression', () => {
const onError = jest.fn()
const onError = vi.fn()
transformWithVText(`<div v-text></div>`, {
onError
})

View File

@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1
exports[`$ unwrapping 1`] = `
"

View File

@ -1,8 +1,9 @@
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]
@ -216,7 +217,7 @@ describe('reactivity/collections', () => {
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)
@ -350,7 +351,7 @@ describe('reactivity/collections', () => {
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)
@ -418,7 +419,7 @@ describe('reactivity/collections', () => {
// #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 = []

View File

@ -1,8 +1,9 @@
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]
@ -182,7 +183,7 @@ describe('reactivity/collections', () => {
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)
@ -283,7 +284,7 @@ describe('reactivity/collections', () => {
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)

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { reactive, effect, toRaw, isReactive } from '../../src'
describe('reactivity/collections', () => {
@ -57,7 +58,7 @@ 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)
@ -128,7 +129,7 @@ describe('reactivity/collections', () => {
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)

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { reactive, isReactive, effect, toRaw } from '../../src'
describe('reactivity/collections', () => {
@ -50,7 +51,7 @@ 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)

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
computed,
reactive,
@ -23,7 +24,7 @@ describe('reactivity/computed', () => {
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
@ -74,8 +75,8 @@ describe('reactivity/computed', () => {
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)
@ -97,8 +98,8 @@ describe('reactivity/computed', () => {
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)
@ -223,7 +224,7 @@ describe('reactivity/computed', () => {
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 })
@ -256,7 +257,7 @@ describe('reactivity/computed', () => {
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 })

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { computed, deferredComputed, effect, ref } from '../src'
describe('deferred computed', () => {
@ -6,7 +7,7 @@ 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)
})
@ -25,7 +26,7 @@ describe('deferred computed', () => {
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)
})
@ -46,9 +47,9 @@ describe('deferred computed', () => {
})
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(() => {
@ -76,9 +77,9 @@ describe('deferred computed', () => {
})
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(() => {
@ -108,9 +109,9 @@ describe('deferred computed', () => {
})
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(() => {
@ -140,9 +141,9 @@ describe('deferred computed', () => {
})
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(() => {
@ -167,7 +168,7 @@ describe('deferred computed', () => {
})
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()

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
ref,
reactive,
@ -16,7 +17,7 @@ import { ITERATE_KEY } from '../src/effect'
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)
})
@ -290,8 +291,8 @@ describe('reactivity/effect', () => {
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)
@ -349,7 +350,7 @@ describe('reactivity/effect', () => {
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)
@ -361,8 +362,8 @@ describe('reactivity/effect', () => {
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)
@ -371,8 +372,8 @@ describe('reactivity/effect', () => {
})
;(['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)
@ -383,7 +384,7 @@ describe('reactivity/effect', () => {
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()
@ -397,8 +398,8 @@ describe('reactivity/effect', () => {
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)
@ -433,7 +434,7 @@ describe('reactivity/effect', () => {
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)
@ -473,7 +474,7 @@ describe('reactivity/effect', () => {
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)
@ -509,7 +510,7 @@ describe('reactivity/effect', () => {
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
@ -518,7 +519,7 @@ describe('reactivity/effect', () => {
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
@ -588,7 +589,7 @@ describe('reactivity/effect', () => {
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]
}
@ -606,9 +607,9 @@ describe('reactivity/effect', () => {
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
@ -680,7 +681,7 @@ describe('reactivity/effect', () => {
it('scheduler', () => {
let dummy
let run: any
const scheduler = jest.fn(() => {
const scheduler = vi.fn(() => {
run = runner
})
const obj = reactive({ foo: 1 })
@ -706,7 +707,7 @@ describe('reactivity/effect', () => {
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 })
@ -745,7 +746,7 @@ describe('reactivity/effect', () => {
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 })
@ -818,7 +819,7 @@ describe('reactivity/effect', () => {
})
it('events: onStop', () => {
const onStop = jest.fn()
const onStop = vi.fn()
const runner = effect(() => {}, {
onStop
})
@ -870,7 +871,7 @@ describe('reactivity/effect', () => {
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)
@ -903,7 +904,7 @@ describe('reactivity/effect', () => {
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)
@ -913,7 +914,7 @@ describe('reactivity/effect', () => {
const obj2 = reactive({ foo: 1 })
const observed2: any = shallowReactive({ obj2 })
const fnSpy2 = jest.fn(() => observed2.obj2)
const fnSpy2 = vi.fn(() => observed2.obj2)
effect(fnSpy2)
@ -942,7 +943,7 @@ describe('reactivity/effect', () => {
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)
@ -955,7 +956,7 @@ describe('reactivity/effect', () => {
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)
@ -968,7 +969,7 @@ describe('reactivity/effect', () => {
test('should track hasOwnProperty', () => {
const obj: any = reactive({})
let has = false
const fnSpy = jest.fn()
const fnSpy = vi.fn()
effect(() => {
fnSpy()

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { nextTick, watch, watchEffect } from '@vue/runtime-core'
import {
reactive,
@ -12,7 +13,7 @@ import {
describe('reactivity/effect/scope', () => {
it('should run', () => {
const fnSpy = jest.fn(() => {})
const fnSpy = vi.fn(() => {})
new EffectScope().run(fnSpy)
expect(fnSpy).toHaveBeenCalledTimes(1)
})
@ -202,7 +203,7 @@ describe('reactivity/effect/scope', () => {
})
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)
@ -231,9 +232,9 @@ describe('reactivity/effect/scope', () => {
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()

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { reactive, isReactive, toRaw } from '../src/reactive'
import { ref, isRef } from '../src/ref'
import { effect } from '../src/effect'
@ -90,7 +91,7 @@ describe('reactivity/reactive/Array', () => {
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)
})
@ -102,7 +103,7 @@ describe('reactivity/reactive/Array', () => {
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)
})
@ -114,7 +115,7 @@ describe('reactivity/reactive/Array', () => {
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)
})

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
ref,
effect,
@ -385,7 +386,7 @@ describe('reactivity/ref', () => {
const obj = reactive({ count: 0 })
const a = ref(obj)
const spy1 = jest.fn(() => a.value)
const spy1 = vi.fn(() => a.value)
effect(spy1)
@ -393,7 +394,7 @@ describe('reactivity/ref', () => {
expect(spy1).toBeCalledTimes(1)
const b = shallowRef(obj)
const spy2 = jest.fn(() => b.value)
const spy2 = vi.fn(() => b.value)
effect(spy2)

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
isReactive,
isShallow,
@ -125,7 +126,7 @@ describe('shallowReactive', () => {
// #1210
test('onTrack on called on objectSpread', () => {
const onTrackFn = jest.fn()
const onTrackFn = vi.fn()
const shallowSet = shallowReactive(new Set())
let a
effect(
@ -170,7 +171,7 @@ describe('shallowReactive', () => {
})
test('onTrack on called on objectSpread', () => {
const onTrackFn = jest.fn()
const onTrackFn = vi.fn()
const shallowArray = shallowReactive([])
let a
effect(

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
defineAsyncComponent,
h,
@ -137,7 +138,7 @@ describe('api: defineAsyncComponent', () => {
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('<!---->')
@ -182,7 +183,7 @@ describe('api: defineAsyncComponent', () => {
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('<!---->')
@ -273,7 +274,7 @@ describe('api: defineAsyncComponent', () => {
render: () => (toggle.value ? h(Foo) : null)
})
const handler = (app.config.errorHandler = jest.fn())
const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
@ -324,7 +325,7 @@ describe('api: defineAsyncComponent', () => {
render: () => h(Foo)
})
const handler = (app.config.errorHandler = jest.fn())
const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
@ -358,7 +359,7 @@ describe('api: defineAsyncComponent', () => {
render: () => h(Foo)
})
const handler = (app.config.errorHandler = jest.fn())
const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('<!---->')
@ -390,7 +391,7 @@ describe('api: defineAsyncComponent', () => {
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)
@ -421,7 +422,7 @@ describe('api: defineAsyncComponent', () => {
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)
@ -512,7 +513,7 @@ describe('api: defineAsyncComponent', () => {
})
})
const handler = (app.config.errorHandler = jest.fn())
const handler = (app.config.errorHandler = vi.fn())
app.mount(root)
expect(serializeInner(root)).toBe('loading')
@ -549,7 +550,7 @@ describe('api: defineAsyncComponent', () => {
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)
@ -593,7 +594,7 @@ describe('api: defineAsyncComponent', () => {
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)
@ -633,7 +634,7 @@ describe('api: defineAsyncComponent', () => {
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)
@ -758,12 +759,12 @@ describe('api: defineAsyncComponent', () => {
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)
@ -803,7 +804,7 @@ describe('api: defineAsyncComponent', () => {
})
test('with KeepAlive', async () => {
const spy = jest.fn()
const spy = vi.fn()
let resolve: (comp: Component) => void
const Foo = defineAsyncComponent(

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
createApp,
h,
@ -145,9 +146,9 @@ describe('api: createApp', () => {
})
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
@ -322,7 +323,7 @@ describe('api: createApp', () => {
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`)
@ -348,7 +349,7 @@ describe('api: createApp', () => {
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`)
@ -368,7 +369,7 @@ describe('api: createApp', () => {
})
describe('config.isNativeTag', () => {
const isNativeTag = jest.fn(tag => tag === 'div')
const isNativeTag = vi.fn(tag => tag === 'div')
test('Component.name', () => {
const Root = {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
onBeforeMount,
h,
@ -23,7 +24,7 @@ import { ITERATE_KEY, DebuggerEvent, TriggerOpTypes } from '@vue/reactivity'
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(``)
})
@ -40,7 +41,7 @@ describe('api: lifecycle hooks', () => {
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>`)
})
@ -58,7 +59,7 @@ describe('api: lifecycle hooks', () => {
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>`)
})
@ -80,12 +81,12 @@ describe('api: lifecycle hooks', () => {
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() {
@ -109,7 +110,7 @@ describe('api: lifecycle hooks', () => {
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>`)
})
@ -130,7 +131,7 @@ describe('api: lifecycle hooks', () => {
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>`)
})
@ -158,7 +159,7 @@ describe('api: lifecycle hooks', () => {
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(`<!---->`)
})
@ -186,7 +187,7 @@ describe('api: lifecycle hooks', () => {
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>`)
})
@ -297,7 +298,7 @@ describe('api: lifecycle hooks', () => {
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 })
@ -333,7 +334,7 @@ describe('api: lifecycle hooks', () => {
it('onRenderTriggered', async () => {
const events: DebuggerEvent[] = []
const onTrigger = jest.fn((e: DebuggerEvent) => {
const onTrigger = vi.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive<{
@ -380,7 +381,7 @@ describe('api: lifecycle hooks', () => {
})
it('runs shared hook fn for each instance', async () => {
const fn = jest.fn()
const fn = vi.fn()
const toggle = ref(true)
const Comp = {
setup() {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
h,
nodeOps,
@ -140,11 +141,11 @@ describe('api: options', () => {
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 = {
@ -186,7 +187,7 @@ describe('api: options', () => {
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)
}
@ -222,9 +223,9 @@ describe('api: options', () => {
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 = {
@ -259,7 +260,7 @@ describe('api: options', () => {
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)
}
@ -1120,7 +1121,7 @@ describe('api: options', () => {
methods: {}
}
const watchSpy = jest.fn()
const watchSpy = vi.fn()
const mixin2 = {
watch: {
mixin3Data: watchSpy

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { ref, reactive } from '@vue/reactivity'
import {
renderToString,
@ -169,7 +170,7 @@ describe('api: setup context', () => {
it('context.emit', async () => {
const count = ref(0)
const spy = jest.fn()
const spy = vi.fn()
const Parent = {
render: () =>

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
ComponentInternalInstance,
createApp,
@ -149,7 +150,7 @@ describe('SFC <script setup> helpers', () => {
})
test('basic', async () => {
const spy = jest.fn()
const spy = vi.fn()
let beforeInstance: ComponentInternalInstance | null = null
let afterInstance: ComponentInternalInstance | null = null
@ -197,7 +198,7 @@ describe('SFC <script setup> helpers', () => {
})
test('error handling', async () => {
const spy = jest.fn()
const spy = vi.fn()
let beforeInstance: ComponentInternalInstance | null = null
let afterInstance: ComponentInternalInstance | null = null

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
watch,
watchEffect,
@ -85,7 +86,7 @@ describe('api: watch', () => {
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()
@ -94,7 +95,7 @@ describe('api: watch', () => {
})
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)
@ -279,7 +280,7 @@ describe('api: watch', () => {
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)
@ -298,7 +299,7 @@ describe('api: watch', () => {
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)
@ -326,7 +327,7 @@ describe('api: watch', () => {
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
@ -364,7 +365,7 @@ describe('api: watch', () => {
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}`
})
@ -393,7 +394,7 @@ describe('api: watch', () => {
it('watchPostEffect', async () => {
const count = ref(0)
let result
const assertion = jest.fn(count => {
const assertion = vi.fn(count => {
result = serializeInner(root) === `${count}`
})
@ -423,7 +424,7 @@ describe('api: watch', () => {
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
@ -470,7 +471,7 @@ describe('api: watch', () => {
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
@ -507,7 +508,7 @@ describe('api: watch', () => {
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' })
@ -529,7 +530,7 @@ describe('api: watch', () => {
// #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' })
@ -726,7 +727,7 @@ describe('api: watch', () => {
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++
@ -736,14 +737,14 @@ describe('api: watch', () => {
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
@ -779,7 +780,7 @@ describe('api: watch', () => {
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()
@ -798,7 +799,7 @@ describe('api: watch', () => {
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 })
@ -833,7 +834,7 @@ describe('api: watch', () => {
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 })
@ -912,7 +913,7 @@ describe('api: watch', () => {
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()
})
@ -927,7 +928,7 @@ describe('api: watch', () => {
// #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(() => {
@ -940,7 +941,7 @@ describe('api: watch', () => {
// #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)
@ -1005,7 +1006,7 @@ describe('api: watch', () => {
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() {},
@ -1023,7 +1024,7 @@ describe('api: watch', () => {
})
test('should not leak `this.proxy` to setup()', () => {
const source = jest.fn()
const source = vi.fn()
const Comp = defineComponent({
render() {},
@ -1042,7 +1043,7 @@ describe('api: watch', () => {
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'],
@ -1077,7 +1078,7 @@ describe('api: watch', () => {
})
test('watching keypath', async () => {
const spy = jest.fn()
const spy = vi.fn()
const Comp = defineComponent({
render() {},
data() {
@ -1107,7 +1108,7 @@ describe('api: watch', () => {
it('watching sources: ref<any[]>', async () => {
const foo = ref([1])
const spy = jest.fn()
const spy = vi.fn()
watch(foo, () => {
spy()
})

View File

@ -1,6 +1,7 @@
// Note: emits and listener fallthrough is tested in
// ./rendererAttrsFallthrough.spec.ts.
import { vi } from 'vitest'
import {
render,
defineComponent,
@ -23,9 +24,9 @@ describe('component: emit', () => {
}
})
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'))
@ -43,7 +44,7 @@ describe('component: emit', () => {
}
})
const fooSpy = jest.fn()
const fooSpy = vi.fn()
const Comp = () =>
h(Foo, {
onTestEvent: fooSpy
@ -61,7 +62,7 @@ describe('component: emit', () => {
}
})
const fooSpy = jest.fn()
const fooSpy = vi.fn()
const Comp = () =>
h(Foo, {
'onTest-event': fooSpy
@ -81,8 +82,8 @@ describe('component: emit', () => {
}
})
const fooSpy = jest.fn()
const barSpy = jest.fn()
const fooSpy = vi.fn()
const barSpy = vi.fn()
const Comp = () =>
// simulate v-on="obj" usage
h(
@ -108,8 +109,8 @@ describe('component: emit', () => {
}
})
const fooSpy = jest.fn()
const barSpy = jest.fn()
const fooSpy = vi.fn()
const barSpy = vi.fn()
const Comp = () =>
h(Foo, {
'onUpdate:fooProp': fooSpy,
@ -129,8 +130,8 @@ describe('component: emit', () => {
}
})
const fn1 = jest.fn()
const fn2 = jest.fn()
const fn1 = vi.fn()
const fn2 = vi.fn()
const App = {
setup() {
@ -256,8 +257,8 @@ describe('component: emit', () => {
this.$emit('bar')
}
})
const fn = jest.fn()
const barFn = jest.fn()
const fn = vi.fn()
const barFn = vi.fn()
render(
h(Foo, {
onFooOnce: fn,
@ -280,8 +281,8 @@ describe('component: emit', () => {
this.$emit('foo')
}
})
const onFoo = jest.fn()
const onFooOnce = jest.fn()
const onFoo = vi.fn()
const onFooOnce = vi.fn()
render(
h(Foo, {
onFoo,
@ -302,8 +303,8 @@ describe('component: emit', () => {
}
})
const fn1 = jest.fn()
const fn2 = jest.fn()
const fn1 = vi.fn()
const fn2 = vi.fn()
const Comp = () =>
h(Foo, {
@ -333,8 +334,8 @@ describe('component: emit', () => {
}
})
const fn1 = jest.fn()
const fn2 = jest.fn()
const fn1 = vi.fn()
const fn2 = vi.fn()
const Comp = () =>
h(Foo, {
@ -364,8 +365,8 @@ describe('component: emit', () => {
}
})
const fn1 = jest.fn()
const fn2 = jest.fn()
const fn1 = vi.fn()
const fn2 = vi.fn()
const Comp = () =>
h(Foo, {
@ -394,7 +395,7 @@ describe('component: emit', () => {
}
})
const fn = jest.fn()
const fn = vi.fn()
const Comp = () =>
h(Foo, {
modelValue: null,
@ -430,7 +431,7 @@ describe('component: emit', () => {
})
test('does not emit after unmount', async () => {
const fn = jest.fn()
const fn = vi.fn()
const Foo = defineComponent({
emits: ['closing'],
async beforeUnmount() {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
ComponentInternalInstance,
getCurrentInstance,
@ -163,8 +164,8 @@ describe('component props', () => {
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: {
@ -536,7 +537,7 @@ describe('component 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 = {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
h,
render,
@ -306,7 +307,7 @@ describe('component: proxy', () => {
// 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

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
ref,
render,
@ -200,7 +201,7 @@ describe('component: slots', () => {
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()

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
nodeOps,
render,
@ -44,28 +45,28 @@ function mockProps(extra: BaseTransitionProps = {}, withKeepAlive = false) {
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 {
@ -86,7 +87,7 @@ function assertCalls(
}
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 {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
h,
TestElement,
@ -43,11 +44,11 @@ describe('KeepAlive', () => {
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',
@ -55,11 +56,11 @@ describe('KeepAlive', () => {
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,
@ -225,7 +226,7 @@ describe('KeepAlive', () => {
render(this: any) {
return h('div', this.msg)
},
activated: jest.fn()
activated: vi.fn()
}
const one = {
name: 'one',
@ -399,18 +400,18 @@ describe('KeepAlive', () => {
})
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([
@ -609,13 +610,13 @@ describe('KeepAlive', () => {
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'
}
@ -670,7 +671,7 @@ describe('KeepAlive', () => {
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 = {
@ -735,8 +736,8 @@ describe('KeepAlive', () => {
}
})
const spyMounted = jest.fn()
const spyUnmounted = jest.fn()
const spyMounted = vi.fn()
const spyUnmounted = vi.fn()
const RouterView = defineComponent({
setup(_, { slots }) {
@ -885,7 +886,7 @@ describe('KeepAlive', () => {
// #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() {
@ -911,12 +912,12 @@ describe('KeepAlive', () => {
// #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',

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
h,
ref,
@ -76,9 +77,9 @@ describe('Suspense', () => {
}
})
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 = {
@ -190,7 +191,7 @@ describe('Suspense', () => {
}
})
const onResolve = jest.fn()
const onResolve = vi.fn()
const Comp = {
setup() {
@ -451,7 +452,7 @@ describe('Suspense', () => {
test('unmount suspense after resolve', async () => {
const toggle = ref(true)
const unmounted = jest.fn()
const unmounted = vi.fn()
const Async = defineAsyncComponent({
setup() {
@ -489,8 +490,8 @@ describe('Suspense', () => {
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() {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
nodeOps,
serializeInner,
@ -440,8 +441,8 @@ describe('renderer: teleport', () => {
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({

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
h,
withDirectives,
@ -23,7 +24,7 @@ describe('directives', () => {
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)
@ -35,7 +36,7 @@ describe('directives', () => {
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)
@ -47,7 +48,7 @@ describe('directives', () => {
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)
@ -61,7 +62,7 @@ describe('directives', () => {
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)
@ -75,7 +76,7 @@ describe('directives', () => {
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)
@ -87,7 +88,7 @@ describe('directives', () => {
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)
@ -158,7 +159,7 @@ describe('directives', () => {
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)
@ -212,7 +213,7 @@ describe('directives', () => {
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)
@ -224,7 +225,7 @@ describe('directives', () => {
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)
@ -236,7 +237,7 @@ describe('directives', () => {
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)
@ -250,7 +251,7 @@ describe('directives', () => {
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)
@ -264,7 +265,7 @@ describe('directives', () => {
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)
@ -276,7 +277,7 @@ describe('directives', () => {
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)
@ -345,10 +346,10 @@ describe('directives', () => {
// #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() {
@ -372,7 +373,7 @@ describe('directives', () => {
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() {
@ -424,7 +425,7 @@ describe('directives', () => {
test('should not throw with unknown directive', async () => {
const d1 = {
mounted: jest.fn()
mounted: vi.fn()
}
const App = {
name: 'App',

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
onMounted,
onErrorCaptured,
@ -15,7 +16,7 @@ import {
describe('error handling', () => {
test('propagation', () => {
const err = new Error('foo')
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -53,7 +54,7 @@ describe('error handling', () => {
test('propagation stoppage', () => {
const err = new Error('foo')
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -91,7 +92,7 @@ describe('error handling', () => {
test('async error handling', async () => {
const err = new Error('foo')
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -121,7 +122,7 @@ describe('error handling', () => {
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() {
@ -159,7 +160,7 @@ describe('error handling', () => {
test('setup function', () => {
const err = new Error('foo')
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -186,7 +187,7 @@ describe('error handling', () => {
// 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() {
@ -219,7 +220,7 @@ describe('error handling', () => {
test('in render function', () => {
const err = new Error('foo')
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -248,7 +249,7 @@ describe('error handling', () => {
const ref = () => {
throw err
}
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -268,7 +269,7 @@ describe('error handling', () => {
test('in effect', () => {
const err = new Error('foo')
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -295,7 +296,7 @@ describe('error handling', () => {
test('in watch getter', () => {
const err = new Error('foo')
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -325,7 +326,7 @@ describe('error handling', () => {
test('in watch callback', async () => {
const err = new Error('foo')
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -360,7 +361,7 @@ describe('error handling', () => {
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() {
@ -393,7 +394,7 @@ describe('error handling', () => {
test('in component event handler via emit', () => {
const err = new Error('foo')
const fn = jest.fn()
const fn = vi.fn()
const Comp = {
setup() {
@ -423,7 +424,7 @@ describe('error handling', () => {
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() {
@ -455,7 +456,7 @@ describe('error handling', () => {
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>) => () => {
@ -497,13 +498,13 @@ describe('error handling', () => {
})
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() {
@ -543,7 +544,7 @@ describe('error handling', () => {
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() {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { HMRRuntime } from '../src/hmr'
import '../src/hmr'
import { ComponentOptions, InternalRenderFunction } from '../src/component'
@ -117,8 +118,8 @@ describe('hot module replacement', () => {
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,
@ -155,10 +156,10 @@ describe('hot module replacement', () => {
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,
@ -221,8 +222,8 @@ describe('hot module replacement', () => {
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 = {
@ -467,8 +468,8 @@ describe('hot module replacement', () => {
// #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,

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
createSSRApp,
h,
@ -134,7 +135,7 @@ describe('SSR hydration', () => {
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>',
() =>
@ -171,7 +172,7 @@ describe('SSR hydration', () => {
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>',
() =>
@ -222,7 +223,7 @@ describe('SSR hydration', () => {
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-->`
@ -262,8 +263,8 @@ describe('SSR hydration', () => {
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' }, [
@ -329,8 +330,8 @@ describe('SSR hydration', () => {
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'),
@ -453,7 +454,7 @@ describe('SSR hydration', () => {
// 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 = {
@ -564,7 +565,7 @@ describe('SSR hydration', () => {
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
@ -591,7 +592,7 @@ describe('SSR hydration', () => {
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
@ -653,7 +654,7 @@ describe('SSR hydration', () => {
}
})
const done = jest.fn()
const done = vi.fn()
const App = {
template: `
<Suspense @resolve="done">
@ -710,7 +711,7 @@ describe('SSR hydration', () => {
})
test('async component', async () => {
const spy = jest.fn()
const spy = vi.fn()
const Comp = () =>
h(
'button',

View File

@ -1,4 +1,5 @@
// using DOM renderer because this case is mostly DOM-specific
import { vi } from 'vitest'
import {
h,
render,
@ -18,8 +19,8 @@ import { PatchFlags } from '@vue/shared/src'
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() {
@ -83,8 +84,8 @@ describe('attribute fallthrough', () => {
})
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)
@ -141,8 +142,8 @@ describe('attribute fallthrough', () => {
})
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)
@ -197,9 +198,9 @@ describe('attribute fallthrough', () => {
})
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() {
@ -385,7 +386,7 @@ describe('attribute fallthrough', () => {
})
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() {
@ -580,7 +581,7 @@ describe('attribute fallthrough', () => {
}
})
const onClick = jest.fn()
const onClick = vi.fn()
const App = {
render() {
return h(Child, {
@ -611,7 +612,7 @@ describe('attribute fallthrough', () => {
}
Child.emits = ['click']
const onClick = jest.fn()
const onClick = vi.fn()
const App = {
render() {
return h(Child, {
@ -631,7 +632,7 @@ describe('attribute fallthrough', () => {
})
it('should support fallthrough for fragments with single element + comments', () => {
const click = jest.fn()
const click = vi.fn()
const Hello = {
setup() {
@ -673,7 +674,7 @@ describe('attribute fallthrough', () => {
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() {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
ref,
h,
@ -91,7 +92,7 @@ describe('renderer: component', () => {
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')
@ -145,8 +146,8 @@ describe('renderer: component', () => {
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: {
@ -267,7 +268,7 @@ describe('renderer: component', () => {
setup() {
return () => h(Child)
},
updated: jest.fn()
updated: vi.fn()
}
const root = nodeOps.createElement('div')
@ -327,7 +328,7 @@ describe('renderer: component', () => {
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() {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
h,
Fragment,
@ -343,8 +344,8 @@ describe('renderer: optimized mode', () => {
})
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() {
@ -469,7 +470,7 @@ describe('renderer: optimized mode', () => {
// 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)
@ -490,8 +491,8 @@ describe('renderer: optimized mode', () => {
// #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)
@ -830,7 +831,7 @@ describe('renderer: optimized mode', () => {
// #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) {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
ref,
nodeOps,
@ -83,7 +84,7 @@ describe('api: template refs', () => {
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)
@ -92,8 +93,8 @@ describe('api: template refs', () => {
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 }))
@ -112,7 +113,7 @@ describe('api: template refs', () => {
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(
@ -181,7 +182,7 @@ describe('api: template refs', () => {
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()
@ -273,7 +274,7 @@ describe('api: template refs', () => {
// #1834
test('exchange refs', async () => {
const refToggle = ref(false)
const spy = jest.fn()
const spy = vi.fn()
const Comp = {
render(this: any) {
@ -304,7 +305,7 @@ describe('api: template refs', () => {
// #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) {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
queueJob,
nextTick,
@ -187,7 +188,7 @@ describe('scheduler', () => {
// #3806
it('queue preFlushCb inside postFlushCb', async () => {
const spy = jest.fn()
const spy = vi.fn()
const cb = () => spy()
cb.pre = true
queuePostFlushCb(() => {
@ -515,7 +516,7 @@ describe('scheduler', () => {
// #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 = () => {
@ -536,7 +537,7 @@ describe('scheduler', () => {
})
it('flushPreFlushCbs inside a pre job', async () => {
const spy = jest.fn()
const spy = vi.fn()
const job = () => {
spy()
flushPreFlushCbs()

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
createBlock,
createVNode,
@ -120,7 +121,7 @@ describe('vnode', () => {
})
describe('children normalization', () => {
const nop = jest.fn
const nop = vi.fn
test('null', () => {
const vnode = createVNode('p', null, null)

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
h,
render,
@ -40,22 +41,22 @@ describe('renderer: vnode hooks', () => {
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'))
@ -65,22 +66,22 @@ describe('renderer: vnode hooks', () => {
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(

View File

@ -2,7 +2,6 @@ import {
ComponentInternalInstance,
currentInstance,
isInSSRComponentSetup,
LifecycleHooks,
setCurrentInstance,
unsetCurrentInstance
} from './component'
@ -11,6 +10,7 @@ import { callWithAsyncErrorHandling, ErrorTypeStrings } from './errorHandling'
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'

View File

@ -70,6 +70,7 @@ import {
validateCompatConfig
} from './compat/compatConfig'
import { SchedulerJob } from './scheduler'
import { LifecycleHooks } from './enums'
export type Data = Record<string, unknown>
@ -165,23 +166,6 @@ export { ComponentOptions }
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
? {

View File

@ -0,0 +1,16 @@
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'
}

View File

@ -1,7 +1,8 @@
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.
@ -23,7 +24,7 @@ export const enum ErrorCodes {
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',

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { createApp, h } from '../src'
describe('createApp for dom', () => {
@ -23,7 +24,7 @@ describe('createApp for dom', () => {
}
}
const handler = jest.fn(msg => {
const handler = vi.fn(msg => {
expect(msg).toMatch(`Component is missing template or render function`)
})

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
defineAsyncComponent,
defineComponent,
@ -332,7 +333,7 @@ describe('defineCustomElement', () => {
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()
@ -341,7 +342,7 @@ describe('defineCustomElement', () => {
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)
@ -354,9 +355,9 @@ describe('defineCustomElement', () => {
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)
@ -374,7 +375,7 @@ describe('defineCustomElement', () => {
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')
@ -394,7 +395,7 @@ describe('defineCustomElement', () => {
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'))
@ -549,7 +550,7 @@ describe('defineCustomElement', () => {
describe('async', () => {
test('should work', async () => {
const loaderSpy = jest.fn()
const loaderSpy = vi.fn()
const E = defineCustomElement(
defineAsyncComponent(() => {
loaderSpy()

View File

@ -1,14 +1,15 @@
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',

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import {
h,
render,
@ -29,7 +30,7 @@ beforeEach(() => {
describe('vModel', () => {
it('should work with text input', async () => {
const manualListener = jest.fn()
const manualListener = vi.fn()
const component = defineComponent({
data() {
return { value: null }
@ -102,7 +103,7 @@ describe('vModel', () => {
})
it('should work with multiple listeners', async () => {
const spy = jest.fn()
const spy = vi.fn()
const component = defineComponent({
data() {
return { value: null }
@ -131,8 +132,8 @@ describe('vModel', () => {
})
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({

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { patchEvent } from '../../src/modules/events'
import { withModifiers, withKeys } from '@vue/runtime-dom'
@ -21,9 +22,9 @@ describe('runtime-dom: v-on directive', () => {
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()
@ -33,7 +34,7 @@ describe('runtime-dom: v-on directive', () => {
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')
@ -45,7 +46,7 @@ describe('runtime-dom: v-on directive', () => {
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',
@ -79,7 +80,7 @@ describe('runtime-dom: v-on directive', () => {
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')
@ -87,7 +88,7 @@ describe('runtime-dom: v-on directive', () => {
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'))
@ -111,7 +112,7 @@ describe('runtime-dom: v-on directive', () => {
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
@ -127,7 +128,7 @@ describe('runtime-dom: v-on directive', () => {
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)

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { patchProp } from '../src/patchProp'
const timeout = () => new Promise(r => setTimeout(r))
@ -5,7 +6,7 @@ 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()
@ -18,8 +19,8 @@ describe(`runtime-dom: events patching`, () => {
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)
@ -34,8 +35,8 @@ describe(`runtime-dom: events patching`, () => {
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()
@ -45,7 +46,7 @@ describe(`runtime-dom: events patching`, () => {
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'))
@ -55,7 +56,7 @@ describe(`runtime-dom: events patching`, () => {
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()
@ -66,7 +67,7 @@ describe(`runtime-dom: events patching`, () => {
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()
@ -84,14 +85,14 @@ describe(`runtime-dom: events patching`, () => {
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)
@ -102,10 +103,10 @@ describe(`runtime-dom: events patching`, () => {
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()
@ -119,8 +120,8 @@ describe(`runtime-dom: events patching`, () => {
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)
@ -153,8 +154,8 @@ describe(`runtime-dom: events patching`, () => {
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()
@ -178,8 +179,8 @@ describe(`runtime-dom: events patching`, () => {
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'

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { patchProp } from '../src/patchProp'
import { render, h } from '../src'
@ -95,7 +96,7 @@ describe('runtime-dom: props patching', () => {
})
test('innerHTML unmount prev children', () => {
const fn = jest.fn()
const fn = vi.fn()
const comp = {
render: () => 'foo',
unmounted: fn
@ -111,7 +112,7 @@ describe('runtime-dom: props patching', () => {
// #954
test('(svg) innerHTML unmount prev children', () => {
const fn = jest.fn()
const fn = vi.fn()
const comp = {
render: () => 'foo',
unmounted: fn
@ -126,7 +127,7 @@ describe('runtime-dom: props patching', () => {
})
test('textContent unmount prev children', () => {
const fn = jest.fn()
const fn = vi.fn()
const comp = {
render: () => 'foo',
unmounted: fn

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { patchProp } from '../src/patchProp'
describe(`runtime-dom: style patching`, () => {
@ -10,7 +11,7 @@ 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 {

View File

@ -2,6 +2,7 @@
* @jest-environment node
*/
import { vi } from 'vitest'
import {
createApp,
h,
@ -820,8 +821,8 @@ function testRender(type: string, render: typeof renderToString) {
// #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() {
@ -948,8 +949,8 @@ function testRender(type: string, render: typeof renderToString) {
})
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({

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { createSSRApp, defineComponent, h, computed, reactive } from 'vue'
import { renderToString } from '../src/renderToString'
@ -20,7 +21,7 @@ test('computed reactivity during SSR', async () => {
}
}
const getterSpy = jest.fn()
const getterSpy = vi.fn()
const App = defineComponent(async () => {
const msg = computed(() => {

View File

@ -2,6 +2,7 @@
* @jest-environment node
*/
import { vi } from 'vitest'
import { createApp, h, Suspense } from 'vue'
import { renderToString } from '../src/renderToString'
@ -33,7 +34,7 @@ describe('SSR Suspense', () => {
test('reject', async () => {
const Comp = {
errorCaptured: jest.fn(() => false),
errorCaptured: vi.fn(() => false),
render() {
return h(Suspense, null, {
default: h(RejectingAsync),
@ -65,7 +66,7 @@ describe('SSR Suspense', () => {
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)]),
@ -84,7 +85,7 @@ describe('SSR Suspense', () => {
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', [
@ -109,7 +110,7 @@ describe('SSR Suspense', () => {
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', [

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '@vue/runtime-core'
import { CompilerDeprecationTypes } from '../../compiler-core/src'
@ -98,7 +99,7 @@ test('COMPILER_V_BIND_OBJECT_ORDER', () => {
})
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: {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { effect, isReactive } from '@vue/reactivity'
import { h, nextTick } from '@vue/runtime-core'
@ -145,10 +146,10 @@ describe('GLOBAL_EXTEND', () => {
})
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
})
@ -475,7 +476,7 @@ test('local app-level mixin registration should not affect other local apps', ()
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)

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import Vue from '@vue/compat'
import {
DeprecationTypes,
@ -24,8 +25,8 @@ test('GLOBAL_KEY_CODES', () => {
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({

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { Slots } from '../../runtime-core/src/componentSlots'
import { Text } from '../../runtime-core/src/vnode'
@ -49,11 +50,11 @@ test('INSTANCE_DESTROY', () => {
// 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', () => {
@ -157,7 +158,7 @@ describe('INSTANCE_EVENT_EMITTER', () => {
})
it('$off event + fn', () => {
const spy2 = jest.fn()
const spy2 = vi.fn()
vm.$on('test', spy)
vm.$on('test', spy2)
vm.$off('test', spy)
@ -173,7 +174,7 @@ describe('INSTANCE_EVENT_EMITTER', () => {
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()
@ -187,7 +188,7 @@ describe('INSTANCE_EVENT_HOOKS', () => {
})
test('via template', () => {
const spy = jest.fn()
const spy = vi.fn()
new Vue({
template: `<child @hook:mounted="spy"/>`,
methods: { spy },

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'
import {
@ -47,7 +48,7 @@ test('mode as function', () => {
})
test('WATCH_ARRAY', async () => {
const spy = jest.fn()
const spy = vi.fn()
const vm = new Vue({
data() {
return {
@ -114,7 +115,7 @@ test('PROPS_DEFAULT_THIS', () => {
})
test('V_ON_KEYCODE_MODIFIER', () => {
const spy = jest.fn()
const spy = vi.fn()
const vm = new Vue({
template: `<input @keyup.1="spy">`,
methods: { spy }
@ -131,11 +132,11 @@ test('V_ON_KEYCODE_MODIFIER', () => {
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 = () =>

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'
import {
@ -84,8 +85,8 @@ test('data deep merge w/ extended constructor', () => {
})
test('beforeDestroy/destroyed', async () => {
const beforeDestroy = jest.fn()
const destroyed = jest.fn()
const beforeDestroy = vi.fn()
const destroyed = vi.fn()
const child = {
template: `foo`,
@ -116,8 +117,8 @@ test('beforeDestroy/destroyed', async () => {
})
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`,

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { E2E_TIMEOUT, setupPuppeteer } from './e2eUtils'
import path from 'path'
import { h, createApp, Transition, ref, nextTick } from 'vue'
@ -264,12 +265,12 @@ describe('e2e: Transition', () => {
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)
@ -368,12 +369,12 @@ describe('e2e: Transition', () => {
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)
@ -482,7 +483,7 @@ describe('e2e: Transition', () => {
)
test('onEnterCancelled', async () => {
const enterCancelledSpy = jest.fn()
const enterCancelledSpy = vi.fn()
await page().exposeFunction('enterCancelledSpy', enterCancelledSpy)
@ -622,15 +623,15 @@ describe('e2e: Transition', () => {
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)
@ -770,12 +771,12 @@ describe('e2e: Transition', () => {
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)
@ -1219,8 +1220,8 @@ describe('e2e: Transition', () => {
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)
@ -1371,8 +1372,8 @@ describe('e2e: Transition', () => {
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)
@ -1561,12 +1562,12 @@ describe('e2e: Transition', () => {
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)
@ -1667,7 +1668,7 @@ describe('e2e: Transition', () => {
test(
'onLeaveCancelled (v-show only)',
async () => {
const onLeaveCancelledSpy = jest.fn()
const onLeaveCancelledSpy = vi.fn()
await page().exposeFunction('onLeaveCancelledSpy', onLeaveCancelledSpy)
await page().evaluate(() => {
@ -1729,9 +1730,9 @@ describe('e2e: Transition', () => {
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)
@ -1835,9 +1836,9 @@ describe('e2e: Transition', () => {
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)
@ -2199,8 +2200,8 @@ describe('e2e: Transition', () => {
// #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) {

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { E2E_TIMEOUT, setupPuppeteer } from './e2eUtils'
import path from 'path'
import { createApp, ref } from 'vue'
@ -359,15 +360,15 @@ describe('e2e: TransitionGroup', () => {
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)

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { createApp } from '../src'
// https://github.com/vuejs/docs/pull/1890
@ -18,8 +19,8 @@ test('custom element event casing', () => {
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

View File

@ -1,3 +1,4 @@
import { vi } from 'vitest'
import { EMPTY_ARR } from '@vue/shared'
import { createApp, ref, nextTick, reactive } from '../src'
@ -21,11 +22,11 @@ describe('compiler + runtime integration', () => {
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)
@ -166,7 +167,7 @@ describe('compiler + runtime integration', () => {
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 }}`,
@ -203,7 +204,7 @@ describe('compiler + runtime integration', () => {
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() {
@ -226,7 +227,7 @@ describe('compiler + runtime integration', () => {
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: `

View File

@ -53,6 +53,7 @@ importers:
tslib: ^2.4.0
typescript: ^4.8.0
vite: ^4.0.4
vitest: ^0.28.2
vue: workspace:*
devDependencies:
'@babel/types': 7.16.0
@ -104,6 +105,7 @@ importers:
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:
@ -1649,6 +1651,16 @@ packages:
'@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
@ -1897,6 +1909,38 @@ packages:
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'}
@ -2045,6 +2089,11 @@ packages:
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'}
@ -2064,6 +2113,11 @@ packages:
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'}
@ -2117,6 +2171,10 @@ packages:
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'}
@ -2402,6 +2460,11 @@ packages:
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:
@ -2442,6 +2505,19 @@ packages:
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'}
@ -2479,6 +2555,10 @@ packages:
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'}
@ -2538,6 +2618,14 @@ packages:
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'}
@ -3047,6 +3135,13 @@ packages:
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'}
@ -3100,6 +3195,11 @@ packages:
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:
@ -3140,6 +3240,10 @@ packages:
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
@ -3165,6 +3269,10 @@ packages:
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'}
@ -3765,6 +3873,10 @@ packages:
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:
@ -4244,6 +4356,11 @@ packages:
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'}
@ -5024,6 +5141,10 @@ packages:
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:
@ -5238,6 +5359,11 @@ packages:
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'}
@ -5303,6 +5429,12 @@ packages:
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:
@ -5517,6 +5649,15 @@ packages:
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'}
@ -5749,6 +5890,13 @@ packages:
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'}
@ -5874,6 +6022,14 @@ packages:
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'}
@ -5930,6 +6086,14 @@ packages:
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:
@ -6038,6 +6202,15 @@ packages:
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}
@ -6296,6 +6469,10 @@ packages:
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
@ -6724,6 +6901,10 @@ packages:
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
@ -6765,6 +6946,14 @@ packages:
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'}
@ -6845,6 +7034,14 @@ packages:
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'}
@ -6883,6 +7080,15 @@ packages:
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'}
@ -6944,6 +7150,13 @@ packages:
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'}
@ -6981,6 +7194,12 @@ packages:
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'}
@ -7112,6 +7331,20 @@ packages:
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
@ -7281,6 +7514,10 @@ packages:
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'}
@ -7379,6 +7616,29 @@ packages:
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}
@ -7412,6 +7672,41 @@ packages:
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}
@ -7447,6 +7742,61 @@ packages:
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
@ -7530,6 +7880,15 @@ packages:
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'}
@ -7708,6 +8067,11 @@ packages:
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'}

94
scripts/setupVitest.ts Normal file
View File

@ -0,0 +1,94 @@
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 - '
)}`
)
}
})

43
vitest.config.ts Normal file
View File

@ -0,0 +1,43 @@
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'
}
})