diff --git a/test/unit/features/options/lifecycle.spec.ts b/test/unit/features/options/lifecycle.spec.ts
index 245ef1972..03f1dec93 100644
--- a/test/unit/features/options/lifecycle.spec.ts
+++ b/test/unit/features/options/lifecycle.spec.ts
@@ -3,7 +3,7 @@ import Vue from 'vue'
describe('Options lifecycle hooks', () => {
let spy
beforeEach(() => {
- spy = jasmine.createSpy('hook')
+ spy = vi.fn()
})
describe('beforeCreate', () => {
@@ -156,8 +156,8 @@ describe('Options lifecycle hooks', () => {
// #8076
it('should not be called after destroy', done => {
- const beforeUpdate = jasmine.createSpy('beforeUpdate')
- const destroyed = jasmine.createSpy('destroyed')
+ const beforeUpdate = vi.fn()
+ const destroyed = vi.fn()
Vue.component('todo', {
template: '
{{todo.done}}
',
@@ -240,8 +240,8 @@ describe('Options lifecycle hooks', () => {
// #8076
it('should not be called after destroy', done => {
- const updated = jasmine.createSpy('updated')
- const destroyed = jasmine.createSpy('destroyed')
+ const updated = vi.fn()
+ const destroyed = vi.fn()
Vue.component('todo', {
template: '
{{todo.done}}
',
@@ -290,7 +290,7 @@ describe('Options lifecycle hooks', () => {
vm.$destroy()
vm.$destroy()
expect(spy).toHaveBeenCalled()
- expect(spy.calls.count()).toBe(1)
+ expect(spy.mock.calls.length).toBe(1)
})
})
@@ -308,14 +308,14 @@ describe('Options lifecycle hooks', () => {
vm.$destroy()
vm.$destroy()
expect(spy).toHaveBeenCalled()
- expect(spy.calls.count()).toBe(1)
+ expect(spy.mock.calls.length).toBe(1)
})
})
it('should emit hook events', () => {
- const created = jasmine.createSpy()
- const mounted = jasmine.createSpy()
- const destroyed = jasmine.createSpy()
+ const created = vi.fn()
+ const mounted = vi.fn()
+ const destroyed = vi.fn()
const vm = new Vue({
render () {},
beforeCreate () {
diff --git a/test/unit/features/options/mixins.spec.ts b/test/unit/features/options/mixins.spec.ts
index 373f88670..09be22903 100644
--- a/test/unit/features/options/mixins.spec.ts
+++ b/test/unit/features/options/mixins.spec.ts
@@ -111,8 +111,8 @@ describe('Options mixins', () => {
})
it('should accept further extended constructors as mixins', () => {
- const spy1 = jasmine.createSpy('mixinA')
- const spy2 = jasmine.createSpy('mixinB')
+ const spy1 = vi.fn()
+ const spy2 = vi.fn()
const mixinA = Vue.extend({
created: spy1,
diff --git a/test/unit/features/options/props.spec.ts b/test/unit/features/options/props.spec.ts
index 2ada45a05..6a6c1ffde 100644
--- a/test/unit/features/options/props.spec.ts
+++ b/test/unit/features/options/props.spec.ts
@@ -169,56 +169,56 @@ describe('Options props', () => {
it('string', () => {
makeInstance('hello', String)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(123, String)
expect('Expected String with value "123", got Number with value 123').toHaveBeenWarned()
})
it('number', () => {
makeInstance(123, Number)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance('123', Number)
expect('Expected Number with value 123, got String with value "123"').toHaveBeenWarned()
})
it('number & boolean', () => {
makeInstance(123, Number)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(false, Number)
expect('Expected Number, got Boolean with value false').toHaveBeenWarned()
})
it('string & boolean', () => {
makeInstance('hello', String)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(true, String)
expect('Expected String, got Boolean with value true').toHaveBeenWarned()
})
it('boolean', () => {
makeInstance(true, Boolean)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance('123', Boolean)
expect('Expected Boolean, got String with value "123"').toHaveBeenWarned()
})
it('function', () => {
makeInstance(() => {}, Function)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(123, Function)
expect('Expected Function, got Number with value 123').toHaveBeenWarned()
})
it('object', () => {
makeInstance({}, Object)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance([], Object)
expect('Expected Object, got Array').toHaveBeenWarned()
})
it('array', () => {
makeInstance([], Array)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance({}, Array)
expect('Expected Array, got Object').toHaveBeenWarned()
})
@@ -226,18 +226,18 @@ describe('Options props', () => {
it('primitive wrapper objects', () => {
/* eslint-disable no-new-wrappers */
makeInstance(new String('s'), String)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(new Number(1), Number)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(new Boolean(true), Boolean)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
/* eslint-enable no-new-wrappers */
})
if (hasSymbol) {
it('symbol', () => {
makeInstance(Symbol('foo'), Symbol)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance({}, Symbol)
expect('Expected Symbol, got Object').toHaveBeenWarned()
})
@@ -252,12 +252,12 @@ describe('Options props', () => {
expect('Expected String, Number, got Symbol').toHaveBeenWarned()
})
}
-
+
if (typeof BigInt !== 'undefined') {
/* global BigInt */
it('bigint', () => {
makeInstance(BigInt(100), BigInt)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance({}, BigInt)
expect('Expected BigInt, got Object').toHaveBeenWarned()
})
@@ -266,28 +266,28 @@ describe('Options props', () => {
it('custom constructor', () => {
function Class () {}
makeInstance(new Class(), Class)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance({}, Class)
expect('type check failed').toHaveBeenWarned()
})
it('multiple types', () => {
makeInstance([], [Array, Number, Boolean])
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance({}, [Array, Number, Boolean])
expect('Expected Array, Number, Boolean, got Object').toHaveBeenWarned()
})
it('custom validator', () => {
makeInstance(123, null, v => v === 123)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(123, null, v => v === 234)
expect('custom validator check failed').toHaveBeenWarned()
})
it('type check + custom validator', () => {
makeInstance(123, Number, v => v === 123)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(123, Number, v => v === 234)
expect('custom validator check failed').toHaveBeenWarned()
makeInstance(123, String, v => v === 123)
@@ -296,7 +296,7 @@ describe('Options props', () => {
it('multiple types + custom validator', () => {
makeInstance(123, [Number, String, Boolean], v => v === 123)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(123, [Number, String, Boolean], v => v === 234)
expect('custom validator check failed').toHaveBeenWarned()
makeInstance(123, [String, Boolean], v => v === 123)
@@ -305,31 +305,31 @@ describe('Options props', () => {
it('optional with type + null/undefined', () => {
makeInstance(undefined, String)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(null, String)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
})
it('required with type + null/undefined', () => {
makeInstance(undefined, String, null, true)
- expect(console.error.calls.count()).toBe(1)
+ expect(console.error.mock.calls.length).toBe(1)
expect('Expected String').toHaveBeenWarned()
makeInstance(null, Boolean, null, true)
- expect(console.error.calls.count()).toBe(2)
+ expect(console.error.mock.calls.length).toBe(2)
expect('Expected Boolean').toHaveBeenWarned()
})
it('optional prop of any type (type: true or prop: true)', () => {
makeInstance(1, true)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance('any', true)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance({}, true)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(undefined, true)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
makeInstance(null, true)
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
})
})
@@ -468,12 +468,12 @@ describe('Options props', () => {
}
}
}).$mount()
- expect(console.error.calls.count()).toBe(0)
+ expect(console.error.mock.calls.length).toBe(0)
})
// #3453
it('should not fire watcher on object/array props when parent re-renders', done => {
- const spy = jasmine.createSpy()
+ const spy = vi.fn()
const vm = new Vue({
data: {
arr: []
@@ -497,7 +497,7 @@ describe('Options props', () => {
// #4090
it('should not trigger watcher on default value', done => {
- const spy = jasmine.createSpy()
+ const spy = vi.fn()
const vm = new Vue({
template: `
`,
data: {
@@ -526,14 +526,14 @@ describe('Options props', () => {
expect(spy).not.toHaveBeenCalled()
vm.b = {}
}).then(() => {
- expect(spy.calls.count()).toBe(1)
+ expect(spy.mock.calls.length).toBe(1)
}).then(() => {
vm.b = undefined
}).then(() => {
- expect(spy.calls.count()).toBe(2)
+ expect(spy.mock.calls.length).toBe(2)
vm.a++
}).then(() => {
- expect(spy.calls.count()).toBe(2)
+ expect(spy.mock.calls.length).toBe(2)
}).then(done)
})
diff --git a/test/unit/features/options/renderError.spec.ts b/test/unit/features/options/renderError.spec.ts
index 4b4b04be8..d25c4f48a 100644
--- a/test/unit/features/options/renderError.spec.ts
+++ b/test/unit/features/options/renderError.spec.ts
@@ -27,7 +27,7 @@ describe('Options renderError', () => {
})
it('should pass on errors in renderError to global handler', () => {
- const spy = Vue.config.errorHandler = jasmine.createSpy()
+ const spy = Vue.config.errorHandler = vi.fn()
const err = new Error('renderError')
const vm = new Vue({
render () {
diff --git a/test/unit/features/options/watch.spec.ts b/test/unit/features/options/watch.spec.ts
index 3938bd33c..234852a03 100644
--- a/test/unit/features/options/watch.spec.ts
+++ b/test/unit/features/options/watch.spec.ts
@@ -5,7 +5,7 @@ import { finished } from 'stream';
describe('Options watch', () => {
let spy
beforeEach(() => {
- spy = jasmine.createSpy('watch')
+ spy = vi.fn()
})
testObjectOption('watch')
@@ -48,7 +48,7 @@ describe('Options watch', () => {
})
it('multiple cbs (after option merge)', done => {
- const spy1 = jasmine.createSpy('watch')
+ const spy1 = vi.fn()
const Test = Vue.extend({
watch: {
a: spy1
@@ -107,8 +107,8 @@ describe('Options watch', () => {
})
it('correctly merges multiple extends', done => {
- const spy2 = jasmine.createSpy('A')
- const spy3 = jasmine.createSpy('B')
+ const spy2 = vi.fn()
+ const spy3 = vi.fn()
const A = Vue.extend({
data: function () {
return {
diff --git a/test/unit/features/transition/transition-group.spec.ts b/test/unit/features/transition/transition-group.spec.ts
index 2988d5bff..f109a8c26 100644
--- a/test/unit/features/transition/transition-group.spec.ts
+++ b/test/unit/features/transition/transition-group.spec.ts
@@ -177,9 +177,9 @@ if (!isIE9) {
it('events', done => {
let next
- const beforeEnterSpy = jasmine.createSpy()
- const afterEnterSpy = jasmine.createSpy()
- const afterLeaveSpy = jasmine.createSpy()
+ const beforeEnterSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
+ const afterLeaveSpy = vi.fn()
const vm = new Vue({
template: `
@@ -219,7 +219,7 @@ if (!isIE9) {
`
d
` +
``
)
- expect(beforeEnterSpy.calls.count()).toBe(1)
+ expect(beforeEnterSpy.mock.calls.length).toBe(1)
}).thenWaitFor(_next => { next = _next }).then(() => {
expect(vm.$el.innerHTML).toBe(
`
` +
@@ -229,7 +229,7 @@ if (!isIE9) {
`d
` +
``
)
- expect(afterEnterSpy.calls.count()).toBe(1)
+ expect(afterEnterSpy.mock.calls.length).toBe(1)
vm.items.shift()
}).thenWaitFor(_next => { next = _next }).then(() => {
expect(vm.$el.innerHTML).toBe(
@@ -239,7 +239,7 @@ if (!isIE9) {
`
d
` +
``
)
- expect(afterLeaveSpy.calls.count()).toBe(1)
+ expect(afterLeaveSpy.mock.calls.length).toBe(1)
}).then(done)
})
diff --git a/test/unit/features/transition/transition.spec.ts b/test/unit/features/transition/transition.spec.ts
index c258ae711..dc992e753 100644
--- a/test/unit/features/transition/transition.spec.ts
+++ b/test/unit/features/transition/transition.spec.ts
@@ -137,8 +137,8 @@ if (!isIE9) {
})
it('inline transition object', done => {
- const enter = jasmine.createSpy('enter')
- const leave = jasmine.createSpy('leave')
+ const enter = vi.fn()
+ const leave = vi.fn()
const vm = new Vue({
render (h) {
return h('div', null, [
@@ -184,12 +184,12 @@ if (!isIE9) {
})
it('transition events', done => {
- const onLeaveSpy = jasmine.createSpy('leave')
- const onEnterSpy = jasmine.createSpy('enter')
- const beforeLeaveSpy = jasmine.createSpy('beforeLeave')
- const beforeEnterSpy = jasmine.createSpy('beforeEnter')
- const afterLeaveSpy = jasmine.createSpy('afterLeave')
- const afterEnterSpy = jasmine.createSpy('afterEnter')
+ const onLeaveSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const beforeLeaveSpy = vi.fn()
+ const beforeEnterSpy = vi.fn()
+ const afterLeaveSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
const vm = new Vue({
template: `
@@ -259,12 +259,12 @@ if (!isIE9) {
})
it('transition events (v-show)', done => {
- const onLeaveSpy = jasmine.createSpy('leave')
- const onEnterSpy = jasmine.createSpy('enter')
- const beforeLeaveSpy = jasmine.createSpy('beforeLeave')
- const beforeEnterSpy = jasmine.createSpy('beforeEnter')
- const afterLeaveSpy = jasmine.createSpy('afterLeave')
- const afterEnterSpy = jasmine.createSpy('afterEnter')
+ const onLeaveSpy = vi.fn()
+ const onEnterSpy = vi.fn()
+ const beforeLeaveSpy = vi.fn()
+ const beforeEnterSpy = vi.fn()
+ const afterLeaveSpy = vi.fn()
+ const afterEnterSpy = vi.fn()
const vm = new Vue({
template: `
@@ -386,8 +386,8 @@ if (!isIE9) {
})
it('css: false', done => {
- const enterSpy = jasmine.createSpy('enter')
- const leaveSpy = jasmine.createSpy('leave')
+ const enterSpy = vi.fn()
+ const leaveSpy = vi.fn()
const vm = new Vue({
template: `
@@ -415,8 +415,8 @@ if (!isIE9) {
})
it('no transition detected', done => {
- const enterSpy = jasmine.createSpy('enter')
- const leaveSpy = jasmine.createSpy('leave')
+ const enterSpy = vi.fn()
+ const leaveSpy = vi.fn()
const vm = new Vue({
template: '
',
data: { ok: true },
@@ -442,7 +442,7 @@ if (!isIE9) {
})
it('enterCancelled', done => {
- const spy = jasmine.createSpy('enterCancelled')
+ const spy = vi.fn()
const vm = new Vue({
template: `
@@ -476,7 +476,7 @@ if (!isIE9) {
})
it('should remove stale leaving elements', done => {
- const spy = jasmine.createSpy('afterLeave')
+ const spy = vi.fn()
const vm = new Vue({
template: `
@@ -579,7 +579,7 @@ if (!isIE9) {
})
it('leaveCancelled (v-show only)', done => {
- const spy = jasmine.createSpy('leaveCancelled')
+ const spy = vi.fn()
const vm = new Vue({
template: `
diff --git a/test/unit/modules/compiler/codegen.spec.ts b/test/unit/modules/compiler/codegen.spec.ts
index a31f751d6..5c18388d6 100644
--- a/test/unit/modules/compiler/codegen.spec.ts
+++ b/test/unit/modules/compiler/codegen.spec.ts
@@ -622,7 +622,7 @@ describe('codegen', () => {
`with(this){return _c("myComponent",{tag:"div"})}`
)
expect('Inline-template components must have exactly one child element.').toHaveBeenWarned()
- expect(console.error.calls.count()).toBe(3)
+ expect(console.error.mock.calls.length).toBe(3)
})
it('generate static trees inside v-for', () => {
diff --git a/test/unit/modules/compiler/parser.spec.ts b/test/unit/modules/compiler/parser.spec.ts
index b47de5813..1e6f15673 100644
--- a/test/unit/modules/compiler/parser.spec.ts
+++ b/test/unit/modules/compiler/parser.spec.ts
@@ -676,8 +676,8 @@ describe('parser', () => {
it('pre/post transforms', () => {
const options = extend({}, baseOptions)
- const spy1 = jasmine.createSpy('preTransform')
- const spy2 = jasmine.createSpy('postTransform')
+ const spy1 = vi.fn()
+ const spy2 = vi.fn()
options.modules = options.modules.concat([{
preTransformNode (el) {
spy1(el.tag)
diff --git a/test/unit/modules/observer/observer.spec.ts b/test/unit/modules/observer/observer.spec.ts
index f175ae3d8..698931dce 100644
--- a/test/unit/modules/observer/observer.spec.ts
+++ b/test/unit/modules/observer/observer.spec.ts
@@ -187,7 +187,7 @@ describe('Observer', () => {
this.deps.push(dep)
dep.addSub(this)
},
- update: jasmine.createSpy()
+ update: vi.fn()
}
// collect dep
Dep.target = watcher
@@ -195,10 +195,10 @@ describe('Observer', () => {
Dep.target = null
expect(watcher.deps.length).toBe(3) // obj.a + a + a.b
obj.a.b = 3
- expect(watcher.update.calls.count()).toBe(1)
+ expect(watcher.update.mock.calls.length).toBe(1)
// swap object
obj.a = { b: 4 }
- expect(watcher.update.calls.count()).toBe(2)
+ expect(watcher.update.mock.calls.length).toBe(2)
watcher.deps = []
Dep.target = watcher
@@ -208,10 +208,10 @@ describe('Observer', () => {
expect(watcher.deps.length).toBe(4)
// set on the swapped object
obj.a.b = 5
- expect(watcher.update.calls.count()).toBe(3)
+ expect(watcher.update.mock.calls.length).toBe(3)
// should not trigger on NaN -> NaN set
obj.c = NaN
- expect(watcher.update.calls.count()).toBe(3)
+ expect(watcher.update.mock.calls.length).toBe(3)
})
it('observing object prop change on defined property', () => {
@@ -242,22 +242,22 @@ describe('Observer', () => {
spyOn(dep1, 'notify')
setProp(obj1, 'b', 2)
expect(obj1.b).toBe(2)
- expect(dep1.notify.calls.count()).toBe(1)
+ expect(dep1.notify.mock.calls.length).toBe(1)
delProp(obj1, 'a')
expect(hasOwn(obj1, 'a')).toBe(false)
- expect(dep1.notify.calls.count()).toBe(2)
+ expect(dep1.notify.mock.calls.length).toBe(2)
// set existing key, should be a plain set and not
// trigger own ob's notify
setProp(obj1, 'b', 3)
expect(obj1.b).toBe(3)
- expect(dep1.notify.calls.count()).toBe(2)
+ expect(dep1.notify.mock.calls.length).toBe(2)
// set non-existing key
setProp(obj1, 'c', 1)
expect(obj1.c).toBe(1)
- expect(dep1.notify.calls.count()).toBe(3)
+ expect(dep1.notify.mock.calls.length).toBe(3)
// should ignore deleting non-existing key
delProp(obj1, 'a')
- expect(dep1.notify.calls.count()).toBe(3)
+ expect(dep1.notify.mock.calls.length).toBe(3)
// should work on non-observed objects
const obj2 = { a: 1 }
delProp(obj2, 'a')
@@ -270,10 +270,10 @@ describe('Observer', () => {
spyOn(dep3, 'notify')
setProp(obj3, 'b', 2)
expect(obj3.b).toBe(2)
- expect(dep3.notify.calls.count()).toBe(1)
+ expect(dep3.notify.mock.calls.length).toBe(1)
delProp(obj3, 'a')
expect(hasOwn(obj3, 'a')).toBe(false)
- expect(dep3.notify.calls.count()).toBe(2)
+ expect(dep3.notify.mock.calls.length).toBe(2)
// set and delete non-numeric key on array
const arr2 = ['a']
const ob2 = observe(arr2)
@@ -281,10 +281,10 @@ describe('Observer', () => {
spyOn(dep2, 'notify')
setProp(arr2, 'b', 2)
expect(arr2.b).toBe(2)
- expect(dep2.notify.calls.count()).toBe(1)
+ expect(dep2.notify.mock.calls.length).toBe(1)
delProp(arr2, 'b')
expect(hasOwn(arr2, 'b')).toBe(false)
- expect(dep2.notify.calls.count()).toBe(2)
+ expect(dep2.notify.mock.calls.length).toBe(2)
})
it('warning set/delete on a Vue instance', done => {
@@ -339,7 +339,7 @@ describe('Observer', () => {
arr.splice(0, 0, objs[2])
arr.sort()
arr.reverse()
- expect(dep.notify.calls.count()).toBe(7)
+ expect(dep.notify.mock.calls.length).toBe(7)
// inserted elements should be observed
objs.forEach(obj => {
expect(obj.__ob__ instanceof Observer).toBe(true)
diff --git a/test/unit/modules/observer/scheduler.spec.ts b/test/unit/modules/observer/scheduler.spec.ts
index 20409957e..f17f75f94 100644
--- a/test/unit/modules/observer/scheduler.spec.ts
+++ b/test/unit/modules/observer/scheduler.spec.ts
@@ -12,7 +12,7 @@ function queueWatcher (watcher) {
describe('Scheduler', () => {
let spy
beforeEach(() => {
- spy = jasmine.createSpy('scheduler')
+ spy = vi.fn()
})
it('queueWatcher', done => {
@@ -20,7 +20,7 @@ describe('Scheduler', () => {
run: spy
})
waitForUpdate(() => {
- expect(spy.calls.count()).toBe(1)
+ expect(spy.mock.calls.length).toBe(1)
}).then(done)
})
@@ -34,7 +34,7 @@ describe('Scheduler', () => {
run: spy
})
waitForUpdate(() => {
- expect(spy.calls.count()).toBe(1)
+ expect(spy.mock.calls.length).toBe(1)
}).then(done)
})
@@ -49,7 +49,7 @@ describe('Scheduler', () => {
run () { queueWatcher(job) }
})
waitForUpdate(() => {
- expect(spy.calls.count()).toBe(2)
+ expect(spy.mock.calls.length).toBe(2)
}).then(done)
})
diff --git a/test/unit/modules/observer/watcher.spec.ts b/test/unit/modules/observer/watcher.spec.ts
index 724a3cc86..810a72b6d 100644
--- a/test/unit/modules/observer/watcher.spec.ts
+++ b/test/unit/modules/observer/watcher.spec.ts
@@ -16,7 +16,7 @@ describe('Watcher', () => {
msg: 'yo'
}
}).$mount()
- spy = jasmine.createSpy('watcher')
+ spy = vi.fn()
})
it('path', done => {
@@ -44,7 +44,7 @@ describe('Watcher', () => {
waitForUpdate(() => {
expect(watcher1.value).toBe(123)
expect(watcher2.value).toBeUndefined()
- expect(spy.calls.count()).toBe(1)
+ expect(spy.mock.calls.length).toBe(1)
expect(spy).toHaveBeenCalledWith(123, undefined)
}).then(done)
})
@@ -85,11 +85,11 @@ describe('Watcher', () => {
vm.b = { c: [{ a: 1 }] }
}).then(() => {
expect(spy).toHaveBeenCalledWith(vm.b, oldB)
- expect(spy.calls.count()).toBe(2)
+ expect(spy.mock.calls.length).toBe(2)
vm.b.c[0].a = 2
}).then(() => {
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
- expect(spy.calls.count()).toBe(3)
+ expect(spy.mock.calls.length).toBe(3)
}).then(done)
})
@@ -110,11 +110,11 @@ describe('Watcher', () => {
Vue.set(vm.b, '_', vm.b)
waitForUpdate(() => {
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
- expect(spy.calls.count()).toBe(1)
+ expect(spy.mock.calls.length).toBe(1)
vm.b._.c = 1
}).then(() => {
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
- expect(spy.calls.count()).toBe(2)
+ expect(spy.mock.calls.length).toBe(2)
}).then(done)
})
@@ -123,10 +123,10 @@ describe('Watcher', () => {
Vue.set(vm.b, 'e', 123)
waitForUpdate(() => {
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
- expect(spy.calls.count()).toBe(1)
+ expect(spy.mock.calls.length).toBe(1)
Vue.delete(vm.b, 'e')
}).then(() => {
- expect(spy.calls.count()).toBe(2)
+ expect(spy.mock.calls.length).toBe(2)
}).then(done)
})
diff --git a/test/unit/modules/util/error.spec.ts b/test/unit/modules/util/error.spec.ts
index c9152bbb7..2db5e7531 100644
--- a/test/unit/modules/util/error.spec.ts
+++ b/test/unit/modules/util/error.spec.ts
@@ -5,8 +5,8 @@ describe('invokeWithErrorHandling', () => {
if (typeof Promise !== 'undefined') {
it('should errorHandler call once when nested calls return rejected promise', done => {
const originalHandler = Vue.config.errorHandler
- const handler = Vue.config.errorHandler = jasmine.createSpy()
- const userCatch = jasmine.createSpy()
+ const handler = Vue.config.errorHandler = vi.fn()
+ const userCatch = vi.fn()
const err = new Error('fake error')
invokeWithErrorHandling(() => {
@@ -15,7 +15,7 @@ describe('invokeWithErrorHandling', () => {
})
}).catch(userCatch).then(() => {
Vue.config.errorHandler = originalHandler
- expect(handler.calls.count()).toBe(1)
+ expect(handler.mock.calls.length).toBe(1)
expect(userCatch).toHaveBeenCalledWith(err)
done()
})
diff --git a/test/unit/modules/util/next-tick.spec.ts b/test/unit/modules/util/next-tick.spec.ts
index 53f6124c1..353848b48 100644
--- a/test/unit/modules/util/next-tick.spec.ts
+++ b/test/unit/modules/util/next-tick.spec.ts
@@ -23,7 +23,7 @@ describe('nextTick', () => {
})
it('returned Promise should resolve correctly vs callback', done => {
- const spy = jasmine.createSpy()
+ const spy = vi.fn()
nextTick(spy)
nextTick().then(() => {
expect(spy).toHaveBeenCalled()
diff --git a/test/unit/modules/vdom/modules/directive.spec.ts b/test/unit/modules/vdom/modules/directive.spec.ts
index 38c531868..c19b316f0 100644
--- a/test/unit/modules/vdom/modules/directive.spec.ts
+++ b/test/unit/modules/vdom/modules/directive.spec.ts
@@ -5,9 +5,9 @@ import VNode from 'core/vdom/vnode'
describe('vdom directive module', () => {
it('should work', () => {
const directive1 = {
- bind: jasmine.createSpy('bind'),
- update: jasmine.createSpy('update'),
- unbind: jasmine.createSpy('unbind')
+ bind: vi.fn(),
+ update: vi.fn(),
+ unbind: vi.fn()
}
const vm = new Vue({ directives: { directive1 }})
// create
diff --git a/test/unit/modules/vdom/modules/events.spec.ts b/test/unit/modules/vdom/modules/events.spec.ts
index b59935adb..7ee6169f1 100644
--- a/test/unit/modules/vdom/modules/events.spec.ts
+++ b/test/unit/modules/vdom/modules/events.spec.ts
@@ -3,17 +3,17 @@ import VNode from 'core/vdom/vnode'
describe('vdom events module', () => {
it('should attach event handler to element', () => {
- const click = jasmine.createSpy()
+ const click = vi.fn()
const vnode = new VNode('a', { on: { click }})
const elm = patch(null, vnode)
document.body.appendChild(elm)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(1)
})
it('should not duplicate the same listener', () => {
- const click = jasmine.createSpy()
+ const click = vi.fn()
const vnode1 = new VNode('a', { on: { click }})
const vnode2 = new VNode('a', { on: { click }})
@@ -21,90 +21,90 @@ describe('vdom events module', () => {
patch(vnode1, vnode2)
document.body.appendChild(elm)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(1)
})
it('should update different listener', () => {
- const click = jasmine.createSpy()
- const click2 = jasmine.createSpy()
+ const click = vi.fn()
+ const click2 = vi.fn()
const vnode1 = new VNode('a', { on: { click }})
const vnode2 = new VNode('a', { on: { click: click2 }})
const elm = patch(null, vnode1)
document.body.appendChild(elm)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(1)
- expect(click2.calls.count()).toBe(0)
+ expect(click.mock.calls.length).toBe(1)
+ expect(click2.mock.calls.length).toBe(0)
patch(vnode1, vnode2)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(1)
- expect(click2.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(1)
+ expect(click2.mock.calls.length).toBe(1)
})
it('should attach Array of multiple handlers', () => {
- const click = jasmine.createSpy()
+ const click = vi.fn()
const vnode = new VNode('a', { on: { click: [click, click] }})
const elm = patch(null, vnode)
document.body.appendChild(elm)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(2)
+ expect(click.mock.calls.length).toBe(2)
})
it('should update Array of multiple handlers', () => {
- const click = jasmine.createSpy()
- const click2 = jasmine.createSpy()
+ const click = vi.fn()
+ const click2 = vi.fn()
const vnode1 = new VNode('a', { on: { click: [click, click2] }})
const vnode2 = new VNode('a', { on: { click: [click] }})
const elm = patch(null, vnode1)
document.body.appendChild(elm)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(1)
- expect(click2.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(1)
+ expect(click2.mock.calls.length).toBe(1)
patch(vnode1, vnode2)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(2)
- expect(click2.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(2)
+ expect(click2.mock.calls.length).toBe(1)
})
it('should remove handlers that are no longer present', () => {
- const click = jasmine.createSpy()
+ const click = vi.fn()
const vnode1 = new VNode('a', { on: { click }})
const vnode2 = new VNode('a', {})
const elm = patch(null, vnode1)
document.body.appendChild(elm)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(1)
patch(vnode1, vnode2)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(1)
})
it('should remove Array handlers that are no longer present', () => {
- const click = jasmine.createSpy()
+ const click = vi.fn()
const vnode1 = new VNode('a', { on: { click: [click, click] }})
const vnode2 = new VNode('a', {})
const elm = patch(null, vnode1)
document.body.appendChild(elm)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(2)
+ expect(click.mock.calls.length).toBe(2)
patch(vnode1, vnode2)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(2)
+ expect(click.mock.calls.length).toBe(2)
})
// #4650
it('should handle single -> array or array -> single handler changes', () => {
- const click = jasmine.createSpy()
- const click2 = jasmine.createSpy()
- const click3 = jasmine.createSpy()
+ const click = vi.fn()
+ const click2 = vi.fn()
+ const click3 = vi.fn()
const vnode0 = new VNode('a', { on: { click: click }})
const vnode1 = new VNode('a', { on: { click: [click, click2] }})
const vnode2 = new VNode('a', { on: { click: click }})
@@ -113,23 +113,23 @@ describe('vdom events module', () => {
const elm = patch(null, vnode0)
document.body.appendChild(elm)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(1)
- expect(click2.calls.count()).toBe(0)
+ expect(click.mock.calls.length).toBe(1)
+ expect(click2.mock.calls.length).toBe(0)
patch(vnode0, vnode1)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(2)
- expect(click2.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(2)
+ expect(click2.mock.calls.length).toBe(1)
patch(vnode1, vnode2)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(3)
- expect(click2.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(3)
+ expect(click2.mock.calls.length).toBe(1)
patch(vnode2, vnode3)
global.triggerEvent(elm, 'click')
- expect(click.calls.count()).toBe(3)
- expect(click2.calls.count()).toBe(2)
- expect(click3.calls.count()).toBe(1)
+ expect(click.mock.calls.length).toBe(3)
+ expect(click2.mock.calls.length).toBe(2)
+ expect(click3.mock.calls.length).toBe(1)
})
})
diff --git a/test/unit/modules/vdom/patch/edge-cases.spec.ts b/test/unit/modules/vdom/patch/edge-cases.spec.ts
index 294ab9cd9..4342532b6 100644
--- a/test/unit/modules/vdom/patch/edge-cases.spec.ts
+++ b/test/unit/modules/vdom/patch/edge-cases.spec.ts
@@ -270,7 +270,7 @@ describe('vdom patch: edge cases', () => {
// #6803
it('backwards compat with checkbox code generated before 2.4', () => {
- const spy = jasmine.createSpy()
+ const spy = vi.fn()
const vm = new Vue({
data: {
label: 'foobar',
@@ -339,7 +339,7 @@ describe('vdom patch: edge cases', () => {
// #7294
it('should cleanup component inline events on patch when no events are present', done => {
- const log = jasmine.createSpy()
+ const log = vi.fn()
const vm = new Vue({
data: { ok: true },
template: `
@@ -393,7 +393,7 @@ describe('vdom patch: edge cases', () => {
// sometimes we do need to tap into these internal hooks (e.g. in vue-router)
// so make sure it does work
- const inlineHookSpy = jasmine.createSpy('inlineInit')
+ const inlineHookSpy = vi.fn()
const vm = new Vue({
render (h) {
@@ -409,7 +409,7 @@ describe('vdom patch: edge cases', () => {
}).$mount()
expect(vm.$el.textContent).toBe('FooBar')
- expect(inlineHookSpy.calls.count()).toBe(2)
+ expect(inlineHookSpy.mock.calls.length).toBe(2)
})
// #9549