diff --git a/package.json b/package.json
index 9f1440efa..faf4dcd92 100644
--- a/package.json
+++ b/package.json
@@ -102,6 +102,7 @@
"tslib": "^2.4.0",
"typescript": "^4.8.0",
"vite": "^4.0.4",
+ "vitest": "^0.28.2",
"vue": "workspace:*"
}
}
diff --git a/packages/compiler-core/__tests__/parse.spec.ts b/packages/compiler-core/__tests__/parse.spec.ts
index c4e1a3f2f..f86b91608 100644
--- a/packages/compiler-core/__tests__/parse.spec.ts
+++ b/packages/compiler-core/__tests__/parse.spec.ts
@@ -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', {
onError
})
@@ -1844,7 +1845,7 @@ describe('compiler: parse', () => {
baseParse(`
\n\n
\n`)
}).toThrow('Element is missing end tag.')
- const spy = jest.fn()
+ const spy = vi.fn()
const ast = baseParse(`\n\n
\n`, {
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
diff --git a/packages/compiler-core/__tests__/transform.spec.ts b/packages/compiler-core/__tests__/transform.spec.ts
index 89f0ecda5..915ae7a60 100644
--- a/packages/compiler-core/__tests__/transform.spec.ts
+++ b/packages/compiler-core/__tests__/transform.spec.ts
@@ -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
diff --git a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts
index 06fd2e12b..1c90e33fc 100644
--- a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts
@@ -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(``, { onError })
expect(onError.mock.calls[0]).toMatchObject([
{
diff --git a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
index 4db7aa619..b9593c4a4 100644
--- a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
@@ -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`
diff --git a/packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts b/packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts
index fd5bd09c0..e3863f1ed 100644
--- a/packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts
@@ -1,3 +1,4 @@
+import { vi } from 'vitest'
import {
CompilerOptions,
baseParse as parse,
@@ -369,7 +370,7 @@ describe('compiler: transform outlets', () => {
})
test(`error on unexpected custom directive on `, () => {
- const onError = jest.fn()
+ const onError = vi.fn()
const source = ``
parseWithSlots(source, { onError })
const index = source.indexOf('v-foo')
diff --git a/packages/compiler-core/__tests__/transforms/vBind.spec.ts b/packages/compiler-core/__tests__/transforms/vBind.spec.ts
index 27e0ae10c..ea5bdcf3d 100644
--- a/packages/compiler-core/__tests__/transforms/vBind.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/vBind.spec.ts
@@ -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(``, { onError })
const props = (node.codegenNode as VNodeCall).props as ObjectExpression
expect(onError.mock.calls[0][0]).toMatchObject({
diff --git a/packages/compiler-core/__tests__/transforms/vFor.spec.ts b/packages/compiler-core/__tests__/transforms/vFor.spec.ts
index c22b364aa..b07272ef7 100644
--- a/packages/compiler-core/__tests__/transforms/vFor.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/vFor.spec.ts
@@ -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('', { 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('', { 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('', { 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('', { 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('', { onError })
expect(onError).toHaveBeenCalledTimes(1)
@@ -266,7 +267,7 @@ describe('compiler: v-for', () => {
})
test(' key placement', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithForTransform(
`
diff --git a/packages/compiler-core/__tests__/transforms/vIf.spec.ts b/packages/compiler-core/__tests__/transforms/vIf.spec.ts
index 225f6d608..1b42b20c7 100644
--- a/packages/compiler-core/__tests__/transforms/vIf.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/vIf.spec.ts
@@ -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(``, { 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(``, {
onError
@@ -302,7 +303,7 @@ describe('compiler: v-if', () => {
})
test('error on user key', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
// dynamic
parseWithIfTransform(
``,
diff --git a/packages/compiler-core/__tests__/transforms/vModel.spec.ts b/packages/compiler-core/__tests__/transforms/vModel.spec.ts
index 808fb9421..df8f6e024 100644
--- a/packages/compiler-core/__tests__/transforms/vModel.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/vModel.spec.ts
@@ -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('', { 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('', { 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('', { 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('', { onError })
expect(onError).toHaveBeenCalledTimes(0)
})
test('used on scope variable', () => {
- const onError = jest.fn()
+ const onError = vi.fn()
parseWithVModel('', {
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('', {
onError,
bindingMetadata: {
diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts
index 4ed9ea23a..721428a66 100644
--- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts
@@ -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(``, { 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(``, { onError })
expect(onError).not.toHaveBeenCalled()
})
diff --git a/packages/compiler-core/__tests__/transforms/vSlot.spec.ts b/packages/compiler-core/__tests__/transforms/vSlot.spec.ts
index c166f8d16..d111aab6b 100644
--- a/packages/compiler-core/__tests__/transforms/vSlot.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/vSlot.spec.ts
@@ -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 = `foobar`
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 = ``
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 = ``
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 = ``
parseWithSlots(source, { onError })
const index = source.indexOf('v-slot')
diff --git a/packages/compiler-dom/__tests__/transforms/Transition.spec.ts b/packages/compiler-dom/__tests__/transforms/Transition.spec.ts
index 1ae713607..1711c1d26 100644
--- a/packages/compiler-dom/__tests__/transforms/Transition.spec.ts
+++ b/packages/compiler-dom/__tests__/transforms/Transition.spec.ts
@@ -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 = ` expects exactly one child element or component.`
) {
- const spy = jest.fn()
+ const spy = vi.fn()
compile(template.trim(), {
hoistStatic: true,
transformHoist: null,
diff --git a/packages/compiler-dom/__tests__/transforms/vHtml.spec.ts b/packages/compiler-dom/__tests__/transforms/vHtml.spec.ts
index 8c441cef0..294786768 100644
--- a/packages/compiler-dom/__tests__/transforms/vHtml.spec.ts
+++ b/packages/compiler-dom/__tests__/transforms/vHtml.spec.ts
@@ -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(`hello
`, {
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(``, {
onError
})
diff --git a/packages/compiler-dom/__tests__/transforms/vModel.spec.ts b/packages/compiler-dom/__tests__/transforms/vModel.spec.ts
index 3da0b3008..75750a8ce 100644
--- a/packages/compiler-dom/__tests__/transforms/vModel.spec.ts
+++ b/packages/compiler-dom/__tests__/transforms/vModel.spec.ts
@@ -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('', { 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('', { 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('', {
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(``, {
onError
})
diff --git a/packages/compiler-dom/__tests__/transforms/vShow.spec.ts b/packages/compiler-dom/__tests__/transforms/vShow.spec.ts
index 3c70741cb..9fb53974d 100644
--- a/packages/compiler-dom/__tests__/transforms/vShow.spec.ts
+++ b/packages/compiler-dom/__tests__/transforms/vShow.spec.ts
@@ -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(``, { onError })
expect(onError).toHaveBeenCalledTimes(1)
diff --git a/packages/compiler-dom/__tests__/transforms/vText.spec.ts b/packages/compiler-dom/__tests__/transforms/vText.spec.ts
index 75dbda31f..5c500b31f 100644
--- a/packages/compiler-dom/__tests__/transforms/vText.spec.ts
+++ b/packages/compiler-dom/__tests__/transforms/vText.spec.ts
@@ -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(`hello
`, {
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(``, {
onError
})
diff --git a/packages/reactivity-transform/__tests__/__snapshots__/reactivityTransform.spec.ts.snap b/packages/reactivity-transform/__tests__/__snapshots__/reactivityTransform.spec.ts.snap
index 26490ac9d..edccb5f11 100644
--- a/packages/reactivity-transform/__tests__/__snapshots__/reactivityTransform.spec.ts.snap
+++ b/packages/reactivity-transform/__tests__/__snapshots__/reactivityTransform.spec.ts.snap
@@ -1,4 +1,4 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
+// Vitest Snapshot v1
exports[`$ unwrapping 1`] = `
"
diff --git a/packages/reactivity/__tests__/collections/Map.spec.ts b/packages/reactivity/__tests__/collections/Map.spec.ts
index 27ee5b103..aa4874014 100644
--- a/packages/reactivity/__tests__/collections/Map.spec.ts
+++ b/packages/reactivity/__tests__/collections/Map.spec.ts
@@ -1,8 +1,9 @@
+import { vi } from 'vitest'
import { reactive, effect, toRaw, isReactive } from '../../src'
describe('reactivity/collections', () => {
function coverCollectionFn(collection: Map, 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 = []
diff --git a/packages/reactivity/__tests__/collections/Set.spec.ts b/packages/reactivity/__tests__/collections/Set.spec.ts
index 5bd5f2464..4fd29876f 100644
--- a/packages/reactivity/__tests__/collections/Set.spec.ts
+++ b/packages/reactivity/__tests__/collections/Set.spec.ts
@@ -1,8 +1,9 @@
+import { vi } from 'vitest'
import { reactive, effect, isReactive, toRaw } from '../../src'
describe('reactivity/collections', () => {
function coverCollectionFn(collection: Set, 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)
diff --git a/packages/reactivity/__tests__/collections/WeakMap.spec.ts b/packages/reactivity/__tests__/collections/WeakMap.spec.ts
index 31613a065..a8f722458 100644
--- a/packages/reactivity/__tests__/collections/WeakMap.spec.ts
+++ b/packages/reactivity/__tests__/collections/WeakMap.spec.ts
@@ -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)
diff --git a/packages/reactivity/__tests__/collections/WeakSet.spec.ts b/packages/reactivity/__tests__/collections/WeakSet.spec.ts
index 01512b0ee..646f1a235 100644
--- a/packages/reactivity/__tests__/collections/WeakSet.spec.ts
+++ b/packages/reactivity/__tests__/collections/WeakSet.spec.ts
@@ -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)
diff --git a/packages/reactivity/__tests__/computed.spec.ts b/packages/reactivity/__tests__/computed.spec.ts
index 3e4dead83..511579443 100644
--- a/packages/reactivity/__tests__/computed.spec.ts
+++ b/packages/reactivity/__tests__/computed.spec.ts
@@ -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 })
diff --git a/packages/reactivity/__tests__/deferredComputed.spec.ts b/packages/reactivity/__tests__/deferredComputed.spec.ts
index 394028017..51ee5a18b 100644
--- a/packages/reactivity/__tests__/deferredComputed.spec.ts
+++ b/packages/reactivity/__tests__/deferredComputed.spec.ts
@@ -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()
diff --git a/packages/reactivity/__tests__/effect.spec.ts b/packages/reactivity/__tests__/effect.spec.ts
index ed23b1844..035093207 100644
--- a/packages/reactivity/__tests__/effect.spec.ts
+++ b/packages/reactivity/__tests__/effect.spec.ts
@@ -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([])
- 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([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>({})
- 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()
diff --git a/packages/reactivity/__tests__/effectScope.spec.ts b/packages/reactivity/__tests__/effectScope.spec.ts
index a670c1ebc..a19aa0085 100644
--- a/packages/reactivity/__tests__/effectScope.spec.ts
+++ b/packages/reactivity/__tests__/effectScope.spec.ts
@@ -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()
diff --git a/packages/reactivity/__tests__/reactiveArray.spec.ts b/packages/reactivity/__tests__/reactiveArray.spec.ts
index ea7921c6a..c76a0c94b 100644
--- a/packages/reactivity/__tests__/reactiveArray.spec.ts
+++ b/packages/reactivity/__tests__/reactiveArray.spec.ts
@@ -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)
})
diff --git a/packages/reactivity/__tests__/ref.spec.ts b/packages/reactivity/__tests__/ref.spec.ts
index 76add567d..646cc6e67 100644
--- a/packages/reactivity/__tests__/ref.spec.ts
+++ b/packages/reactivity/__tests__/ref.spec.ts
@@ -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)
diff --git a/packages/reactivity/__tests__/shallowReactive.spec.ts b/packages/reactivity/__tests__/shallowReactive.spec.ts
index 4d39fa9b3..297f0dc33 100644
--- a/packages/reactivity/__tests__/shallowReactive.spec.ts
+++ b/packages/reactivity/__tests__/shallowReactive.spec.ts
@@ -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(
diff --git a/packages/runtime-core/__tests__/apiAsyncComponent.spec.ts b/packages/runtime-core/__tests__/apiAsyncComponent.spec.ts
index 45b82923d..a63a950c6 100644
--- a/packages/runtime-core/__tests__/apiAsyncComponent.spec.ts
+++ b/packages/runtime-core/__tests__/apiAsyncComponent.spec.ts
@@ -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(
diff --git a/packages/runtime-core/__tests__/apiCreateApp.spec.ts b/packages/runtime-core/__tests__/apiCreateApp.spec.ts
index 3fb5bb175..7cfce51c1 100644
--- a/packages/runtime-core/__tests__/apiCreateApp.spec.ts
+++ b/packages/runtime-core/__tests__/apiCreateApp.spec.ts
@@ -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 = {
diff --git a/packages/runtime-core/__tests__/apiLifecycle.spec.ts b/packages/runtime-core/__tests__/apiLifecycle.spec.ts
index b7e8de30d..40cf07644 100644
--- a/packages/runtime-core/__tests__/apiLifecycle.spec.ts
+++ b/packages/runtime-core/__tests__/apiLifecycle.spec.ts
@@ -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(``)
})
@@ -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(`0
`)
})
@@ -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(`0
`)
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(`1
`)
})
@@ -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(``)
})
@@ -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(``)
})
@@ -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() {
diff --git a/packages/runtime-core/__tests__/apiOptions.spec.ts b/packages/runtime-core/__tests__/apiOptions.spec.ts
index 96601b787..14c7f3852 100644
--- a/packages/runtime-core/__tests__/apiOptions.spec.ts
+++ b/packages/runtime-core/__tests__/apiOptions.spec.ts
@@ -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
diff --git a/packages/runtime-core/__tests__/apiSetupContext.spec.ts b/packages/runtime-core/__tests__/apiSetupContext.spec.ts
index f00abc9c1..a7dbe3e03 100644
--- a/packages/runtime-core/__tests__/apiSetupContext.spec.ts
+++ b/packages/runtime-core/__tests__/apiSetupContext.spec.ts
@@ -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: () =>
diff --git a/packages/runtime-core/__tests__/apiSetupHelpers.spec.ts b/packages/runtime-core/__tests__/apiSetupHelpers.spec.ts
index e9dd1717b..ca0759cad 100644
--- a/packages/runtime-core/__tests__/apiSetupHelpers.spec.ts
+++ b/packages/runtime-core/__tests__/apiSetupHelpers.spec.ts
@@ -1,3 +1,4 @@
+import { vi } from 'vitest'
import {
ComponentInternalInstance,
createApp,
@@ -149,7 +150,7 @@ describe('SFC