From 52627b95ce3f91916237619da4ca5bdfdbbcfc34 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 20 May 2022 07:56:02 +0800 Subject: [PATCH] test: jasmine.createSpy -> vi.fn --- test/ssr/ssr-bundle-render.spec.ts | 32 +-- .../component/component-keep-alive.spec.ts | 100 ++++---- .../component/component-scoped-slot.spec.ts | 14 +- .../features/component/component-slot.spec.ts | 4 +- .../unit/features/component/component.spec.ts | 2 +- test/unit/features/debug.spec.ts | 2 +- test/unit/features/directives/for.spec.ts | 2 +- test/unit/features/directives/if.spec.ts | 8 +- .../directives/model-component.spec.ts | 2 +- .../features/directives/model-radio.spec.ts | 2 +- .../features/directives/model-select.spec.ts | 10 +- .../features/directives/model-text.spec.ts | 20 +- test/unit/features/directives/on.spec.ts | 236 +++++++++--------- test/unit/features/error-handling.spec.ts | 4 +- test/unit/features/global-api/config.spec.ts | 10 +- test/unit/features/global-api/mixin.spec.ts | 24 +- .../features/instance/methods-data.spec.ts | 14 +- .../features/instance/methods-events.spec.ts | 18 +- .../instance/methods-lifecycle.spec.ts | 6 +- .../unit/features/instance/properties.spec.ts | 12 +- test/unit/features/options/computed.spec.ts | 18 +- test/unit/features/options/directives.spec.ts | 66 ++--- .../features/options/errorCaptured.spec.ts | 14 +- test/unit/features/options/extends.spec.ts | 2 +- test/unit/features/options/functional.spec.ts | 6 +- test/unit/features/options/lifecycle.spec.ts | 20 +- test/unit/features/options/mixins.spec.ts | 4 +- test/unit/features/options/props.spec.ts | 68 ++--- .../unit/features/options/renderError.spec.ts | 2 +- test/unit/features/options/watch.spec.ts | 8 +- .../transition/transition-group.spec.ts | 12 +- .../features/transition/transition.spec.ts | 42 ++-- test/unit/modules/compiler/codegen.spec.ts | 2 +- test/unit/modules/compiler/parser.spec.ts | 4 +- test/unit/modules/observer/observer.spec.ts | 30 +-- test/unit/modules/observer/scheduler.spec.ts | 8 +- test/unit/modules/observer/watcher.spec.ts | 16 +- test/unit/modules/util/error.spec.ts | 6 +- test/unit/modules/util/next-tick.spec.ts | 2 +- .../modules/vdom/modules/directive.spec.ts | 6 +- test/unit/modules/vdom/modules/events.spec.ts | 72 +++--- .../modules/vdom/patch/edge-cases.spec.ts | 8 +- 42 files changed, 469 insertions(+), 469 deletions(-) diff --git a/test/ssr/ssr-bundle-render.spec.ts b/test/ssr/ssr-bundle-render.spec.ts index 184eb98be..a44bc8e1d 100644 --- a/test/ssr/ssr-bundle-render.spec.ts +++ b/test/ssr/ssr-bundle-render.spec.ts @@ -106,8 +106,8 @@ function createAssertions (runInNewContext) { it('render with cache (get/set)', done => { const cache = {} - const get = jasmine.createSpy('get') - const set = jasmine.createSpy('set') + const get = vi.fn() + const set = vi.fn() const options = { runInNewContext, cache: { @@ -138,8 +138,8 @@ function createAssertions (runInNewContext) { renderer.renderToString((err, res) => { expect(err).toBeNull() expect(res).toBe(expected) - expect(get.calls.count()).toBe(2) - expect(set.calls.count()).toBe(1) + expect(get.mock.calls.length).toBe(2) + expect(set.mock.calls.length).toBe(1) done() }) }) @@ -148,9 +148,9 @@ function createAssertions (runInNewContext) { it('render with cache (get/set/has)', done => { const cache = {} - const has = jasmine.createSpy('has') - const get = jasmine.createSpy('get') - const set = jasmine.createSpy('set') + const has = vi.fn() + const get = vi.fn() + const set = vi.fn() const options = { runInNewContext, cache: { @@ -185,9 +185,9 @@ function createAssertions (runInNewContext) { renderer.renderToString((err, res) => { expect(err).toBeNull() expect(res).toBe(expected) - expect(has.calls.count()).toBe(2) - expect(get.calls.count()).toBe(1) - expect(set.calls.count()).toBe(1) + expect(has.mock.calls.length).toBe(2) + expect(get.mock.calls.length).toBe(1) + expect(set.mock.calls.length).toBe(1) done() }) }) @@ -210,10 +210,10 @@ function createAssertions (runInNewContext) { renderer.renderToString(context1, (err, res) => { expect(err).toBeNull() expect(res).toBe(expected) - expect(cache.set.calls.count()).toBe(3) // 3 nested components cached + expect(cache.set.mock.calls.length).toBe(3) // 3 nested components cached const cached = cache.get(key) expect(cached.html).toBe(expected) - expect(cache.get.calls.count()).toBe(1) + expect(cache.get.mock.calls.length).toBe(1) // assert component usage registration for nested children expect(context1.registered).toEqual(['app', 'child', 'grandchild']) @@ -221,8 +221,8 @@ function createAssertions (runInNewContext) { renderer.renderToString(context2, (err, res) => { expect(err).toBeNull() expect(res).toBe(expected) - expect(cache.set.calls.count()).toBe(3) // no new cache sets - expect(cache.get.calls.count()).toBe(2) // 1 get for root + expect(cache.set.mock.calls.length).toBe(3) // no new cache sets + expect(cache.get.mock.calls.length).toBe(2) // 1 get for root expect(context2.registered).toEqual(['app', 'child', 'grandchild']) done() @@ -233,8 +233,8 @@ function createAssertions (runInNewContext) { it('render with cache (opt-out)', done => { const cache = {} - const get = jasmine.createSpy('get') - const set = jasmine.createSpy('set') + const get = vi.fn() + const set = vi.fn() const options = { runInNewContext, cache: { diff --git a/test/unit/features/component/component-keep-alive.spec.ts b/test/unit/features/component/component-keep-alive.spec.ts index 9044a9691..b55f5270d 100644 --- a/test/unit/features/component/component-keep-alive.spec.ts +++ b/test/unit/features/component/component-keep-alive.spec.ts @@ -9,19 +9,19 @@ describe('Component keep-alive', () => { beforeEach(() => { one = { template: '
one
', - created: jasmine.createSpy('one created'), - mounted: jasmine.createSpy('one mounted'), - activated: jasmine.createSpy('one activated'), - deactivated: jasmine.createSpy('one deactivated'), - destroyed: jasmine.createSpy('one destroyed') + created: vi.fn(), + mounted: vi.fn(), + activated: vi.fn(), + deactivated: vi.fn(), + destroyed: vi.fn() } two = { template: '
two
', - created: jasmine.createSpy('two created'), - mounted: jasmine.createSpy('two mounted'), - activated: jasmine.createSpy('two activated'), - deactivated: jasmine.createSpy('two deactivated'), - destroyed: jasmine.createSpy('two destroyed') + created: vi.fn(), + mounted: vi.fn(), + activated: vi.fn(), + deactivated: vi.fn(), + destroyed: vi.fn() } components = { one, @@ -33,11 +33,11 @@ describe('Component keep-alive', () => { function assertHookCalls (component, callCounts) { expect([ - component.created.calls.count(), - component.mounted.calls.count(), - component.activated.calls.count(), - component.deactivated.calls.count(), - component.destroyed.calls.count() + component.created.mock.calls.length, + component.mounted.mock.calls.length, + component.activated.mock.calls.length, + component.deactivated.mock.calls.length, + component.destroyed.mock.calls.length ]).toEqual(callCounts) } @@ -507,21 +507,21 @@ describe('Component keep-alive', () => { }) it('max', done => { - const spyA = jasmine.createSpy() - const spyB = jasmine.createSpy() - const spyC = jasmine.createSpy() - const spyAD = jasmine.createSpy() - const spyBD = jasmine.createSpy() - const spyCD = jasmine.createSpy() + const spyA = vi.fn() + const spyB = vi.fn() + const spyC = vi.fn() + const spyAD = vi.fn() + const spyBD = vi.fn() + const spyCD = vi.fn() function assertCount (calls) { expect([ - spyA.calls.count(), - spyAD.calls.count(), - spyB.calls.count(), - spyBD.calls.count(), - spyC.calls.count(), - spyCD.calls.count() + spyA.mock.calls.length, + spyAD.mock.calls.length, + spyB.mock.calls.length, + spyBD.mock.calls.length, + spyC.mock.calls.length, + spyCD.mock.calls.length ]).toEqual(calls) } @@ -573,21 +573,21 @@ describe('Component keep-alive', () => { }) it('max=1', done => { - const spyA = jasmine.createSpy() - const spyB = jasmine.createSpy() - const spyC = jasmine.createSpy() - const spyAD = jasmine.createSpy() - const spyBD = jasmine.createSpy() - const spyCD = jasmine.createSpy() + const spyA = vi.fn() + const spyB = vi.fn() + const spyC = vi.fn() + const spyAD = vi.fn() + const spyBD = vi.fn() + const spyCD = vi.fn() function assertCount (calls) { expect([ - spyA.calls.count(), - spyAD.calls.count(), - spyB.calls.count(), - spyBD.calls.count(), - spyC.calls.count(), - spyCD.calls.count() + spyA.mock.calls.length, + spyAD.mock.calls.length, + spyB.mock.calls.length, + spyBD.mock.calls.length, + spyC.mock.calls.length, + spyCD.mock.calls.length ]).toEqual(calls) } @@ -651,12 +651,12 @@ describe('Component keep-alive', () => { const Foo = { name: 'foo', template: `
foo
`, - created: jasmine.createSpy('foo') + created: vi.fn() } const Bar = { template: `
bar
`, - created: jasmine.createSpy('bar') + created: vi.fn() } const Child = { @@ -679,8 +679,8 @@ describe('Component keep-alive', () => { }).$mount() function assert (foo, bar) { - expect(Foo.created.calls.count()).toBe(foo) - expect(Bar.created.calls.count()).toBe(bar) + expect(Foo.created.mock.calls.length).toBe(foo) + expect(Bar.created.mock.calls.length).toBe(bar) } expect(vm.$el.textContent).toBe('foo') @@ -703,12 +703,12 @@ describe('Component keep-alive', () => { it('should cache anonymous components if include is not specified', done => { const Foo = { template: `
foo
`, - created: jasmine.createSpy('foo') + created: vi.fn() } const Bar = { template: `
bar
`, - created: jasmine.createSpy('bar') + created: vi.fn() } const Child = { @@ -731,8 +731,8 @@ describe('Component keep-alive', () => { }).$mount() function assert (foo, bar) { - expect(Foo.created.calls.count()).toBe(foo) - expect(Bar.created.calls.count()).toBe(bar) + expect(Foo.created.mock.calls.length).toBe(foo) + expect(Bar.created.mock.calls.length).toBe(bar) } expect(vm.$el.textContent).toBe('foo') @@ -756,7 +756,7 @@ describe('Component keep-alive', () => { it('should not destroy active instance when pruning cache', done => { const Foo = { template: `
foo
`, - destroyed: jasmine.createSpy('destroyed') + destroyed: vi.fn() } const vm = new Vue({ template: ` @@ -1167,7 +1167,7 @@ describe('Component keep-alive', () => { }) it('async components with transition-mode out-in', done => { - const barResolve = jasmine.createSpy('bar resolved') + const barResolve = vi.fn() let next const foo = (resolve) => { setTimeout(() => { @@ -1231,7 +1231,7 @@ describe('Component keep-alive', () => { }).thenWaitFor(_next => { next = _next }).then(() => { // foo afterLeave get called // and bar has already been resolved before afterLeave get called - expect(barResolve.calls.count()).toBe(1) + expect(barResolve.mock.calls.length).toBe(1) expect(vm.$el.innerHTML).toBe('') }).thenWaitFor(nextFrame).then(() => { expect(vm.$el.innerHTML).toBe( diff --git a/test/unit/features/component/component-scoped-slot.spec.ts b/test/unit/features/component/component-scoped-slot.spec.ts index daf999280..4ee111d37 100644 --- a/test/unit/features/component/component-scoped-slot.spec.ts +++ b/test/unit/features/component/component-scoped-slot.spec.ts @@ -899,8 +899,8 @@ describe('Component scoped slot', () => { // 2.6 scoped slot perf optimization it('should have accurate tracking for scoped slots', done => { - const parentUpdate = jasmine.createSpy() - const childUpdate = jasmine.createSpy() + const parentUpdate = vi.fn() + const childUpdate = vi.fn() const vm = new Vue({ template: `
{{ parentCount }}{{ childCount }}
@@ -923,15 +923,15 @@ describe('Component scoped slot', () => { waitForUpdate(() => { expect(vm.$el.innerHTML).toMatch(`1
0
`) // should only trigger parent update - expect(parentUpdate.calls.count()).toBe(1) - expect(childUpdate.calls.count()).toBe(0) + expect(parentUpdate.mock.calls.length).toBe(1) + expect(childUpdate.mock.calls.length).toBe(0) vm.childCount++ }).then(() => { expect(vm.$el.innerHTML).toMatch(`1
1
`) // should only trigger child update - expect(parentUpdate.calls.count()).toBe(1) - expect(childUpdate.calls.count()).toBe(1) + expect(parentUpdate.mock.calls.length).toBe(1) + expect(childUpdate.mock.calls.length).toBe(1) }).then(done) }) @@ -972,7 +972,7 @@ describe('Component scoped slot', () => { // regression #9396 it('should not force update child with no slot content', done => { const Child = { - updated: jasmine.createSpy(), + updated: vi.fn(), template: `
` } diff --git a/test/unit/features/component/component-slot.spec.ts b/test/unit/features/component/component-slot.spec.ts index 16fae8681..ae2f7929e 100644 --- a/test/unit/features/component/component-slot.spec.ts +++ b/test/unit/features/component/component-slot.spec.ts @@ -131,7 +131,7 @@ describe('Component slot', () => { }) it('fallback content should not be evaluated when the parent is providing it', () => { - const test = jasmine.createSpy('test') + const test = vi.fn() const vm = new Vue({ template: 'slot default', components: { @@ -567,7 +567,7 @@ describe('Component slot', () => { // #3518 it('events should not break when slot is toggled by v-if', done => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ template: `
hi
`, methods: { diff --git a/test/unit/features/component/component.spec.ts b/test/unit/features/component/component.spec.ts index 49d4ea53d..587b0eec9 100644 --- a/test/unit/features/component/component.spec.ts +++ b/test/unit/features/component/component.spec.ts @@ -360,7 +360,7 @@ describe('Component', () => { }) it('catch component render error and preserve previous vnode', done => { - const spy = jasmine.createSpy() + const spy = vi.fn() Vue.config.errorHandler = spy const vm = new Vue({ data: { diff --git a/test/unit/features/debug.spec.ts b/test/unit/features/debug.spec.ts index 6f04b18d9..4f510e79c 100644 --- a/test/unit/features/debug.spec.ts +++ b/test/unit/features/debug.spec.ts @@ -88,7 +88,7 @@ found in const vm = new Vue() it('calls warnHandler if warnHandler is set', () => { - Vue.config.warnHandler = jasmine.createSpy() + Vue.config.warnHandler = vi.fn() warn(msg, vm) diff --git a/test/unit/features/directives/for.spec.ts b/test/unit/features/directives/for.spec.ts index eb28b09ca..384c722fe 100644 --- a/test/unit/features/directives/for.spec.ts +++ b/test/unit/features/directives/for.spec.ts @@ -627,7 +627,7 @@ describe('Directive v-for', () => { it('should warn component v-for without keys', () => { const warn = console.warn - console.warn = jasmine.createSpy() + console.warn = vi.fn() new Vue({ template: `
`, components: { diff --git a/test/unit/features/directives/if.spec.ts b/test/unit/features/directives/if.spec.ts index 458f1f924..17851d2d6 100644 --- a/test/unit/features/directives/if.spec.ts +++ b/test/unit/features/directives/if.spec.ts @@ -243,8 +243,8 @@ describe('Directive v-if', () => { }) it('should maintain stable list to avoid unnecessary patches', done => { - const created = jasmine.createSpy() - const destroyed = jasmine.createSpy() + const created = vi.fn() + const destroyed = vi.fn() const vm = new Vue({ data: { ok: true @@ -266,10 +266,10 @@ describe('Directive v-if', () => { } }).$mount() - expect(created.calls.count()).toBe(1) + expect(created.mock.calls.length).toBe(1) vm.ok = false waitForUpdate(() => { - expect(created.calls.count()).toBe(1) + expect(created.mock.calls.length).toBe(1) expect(destroyed).not.toHaveBeenCalled() }).then(done) }) diff --git a/test/unit/features/directives/model-component.spec.ts b/test/unit/features/directives/model-component.spec.ts index 49ff4ddb1..52ccc9ad7 100644 --- a/test/unit/features/directives/model-component.spec.ts +++ b/test/unit/features/directives/model-component.spec.ts @@ -72,7 +72,7 @@ describe('Directive v-model component', () => { }) it('should support customization via model option', done => { - const spy = jasmine.createSpy('update') + const spy = vi.fn() const vm = new Vue({ data: { msg: 'hello' diff --git a/test/unit/features/directives/model-radio.spec.ts b/test/unit/features/directives/model-radio.spec.ts index 3ff4e50bc..9c5198e5e 100644 --- a/test/unit/features/directives/model-radio.spec.ts +++ b/test/unit/features/directives/model-radio.spec.ts @@ -86,7 +86,7 @@ describe('Directive v-model radio', () => { }) it('multiple radios ', (done) => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ data: { selections: ['a', '1'], diff --git a/test/unit/features/directives/model-select.spec.ts b/test/unit/features/directives/model-select.spec.ts index 4fffe73a4..ba8439344 100644 --- a/test/unit/features/directives/model-select.spec.ts +++ b/test/unit/features/directives/model-select.spec.ts @@ -207,7 +207,7 @@ describe('Directive v-model select', () => { }) it('should work with select which has no default selected options', (done) => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ data: { id: 4, @@ -228,7 +228,7 @@ describe('Directive v-model select', () => { document.body.appendChild(vm.$el) vm.testChange = 10 waitForUpdate(() => { - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) }).then(done) }) @@ -296,7 +296,7 @@ describe('Directive v-model select', () => { } it('should work with multiple binding', (done) => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ data: { isMultiple: true, @@ -352,7 +352,7 @@ describe('Directive v-model select', () => { }) it('multiple selects', (done) => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ data: { selections: ['', ''], @@ -520,7 +520,7 @@ describe('Directive v-model select', () => { // #6193 it('should not trigger change event when matching option can be found for each value', done => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ data: { options: ['1'] diff --git a/test/unit/features/directives/model-text.spec.ts b/test/unit/features/directives/model-text.spec.ts index 7cf516746..9b0a74458 100644 --- a/test/unit/features/directives/model-text.spec.ts +++ b/test/unit/features/directives/model-text.spec.ts @@ -136,7 +136,7 @@ describe('Directive v-model text', () => { }) it('multiple inputs', (done) => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ data: { selections: [[1, 2, 3], [4, 5]], @@ -230,7 +230,7 @@ describe('Directive v-model text', () => { // #3468 it('should have higher priority than user v-on events', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ data: { a: 'a' @@ -317,7 +317,7 @@ describe('Directive v-model text', () => { if (!isAndroid) { it('does not trigger extra input events with single compositionend', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ data: { a: 'a' @@ -329,16 +329,16 @@ describe('Directive v-model text', () => { } } }).$mount() - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) vm.$el.value = 'b' triggerEvent(vm.$el, 'input') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$el, 'compositionend') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) }) it('triggers extra input on compositionstart + end', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ data: { a: 'a' @@ -350,13 +350,13 @@ describe('Directive v-model text', () => { } } }).$mount() - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) vm.$el.value = 'b' triggerEvent(vm.$el, 'input') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$el, 'compositionstart') triggerEvent(vm.$el, 'compositionend') - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) }) // #4392 diff --git a/test/unit/features/directives/on.spec.ts b/test/unit/features/directives/on.spec.ts index 46f0f9a98..2f8771be9 100644 --- a/test/unit/features/directives/on.spec.ts +++ b/test/unit/features/directives/on.spec.ts @@ -6,7 +6,7 @@ describe('Directive v-on', () => { beforeEach(() => { vm = null - spy = jasmine.createSpy() + spy = vi.fn() el = document.createElement('div') document.body.appendChild(el) }) @@ -24,7 +24,7 @@ describe('Directive v-on', () => { methods: { foo: spy } }) triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) const args = spy.calls.allArgs() const event = args[0] && args[0][0] || {} @@ -38,7 +38,7 @@ describe('Directive v-on', () => { methods: { foo: spy } }) triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) const args = spy.calls.allArgs() const firstArgs = args[0] @@ -50,7 +50,7 @@ describe('Directive v-on', () => { }) it('should support inline function expression', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() vm = new Vue({ el, template: `
`, @@ -69,7 +69,7 @@ describe('Directive v-on', () => { methods: { foo: spy } }) triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) }) it('should support stop propagation', () => { @@ -130,9 +130,9 @@ describe('Directive v-on', () => { methods: { foo: spy } }) triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) // should no longer trigger + expect(spy.mock.calls.length).toBe(1) // should no longer trigger }) // #4655 @@ -148,14 +148,14 @@ describe('Directive v-on', () => { methods: { foo: spy } }) triggerEvent(vm.$refs.one, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$refs.one, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$refs.two, 'click') - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) triggerEvent(vm.$refs.one, 'click') triggerEvent(vm.$refs.two, 'click') - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) }) it('should support capture and once', () => { @@ -190,7 +190,7 @@ describe('Directive v-on', () => { triggerEvent(vm.$el, 'click') expect(spy).toHaveBeenCalled() triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) }) it('should support keyCode', () => { @@ -233,24 +233,24 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$refs.ctrl, 'keyup') - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) triggerEvent(vm.$refs.ctrl, 'keyup', e => { e.ctrlKey = true }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$refs.shift, 'keyup') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$refs.shift, 'keyup', e => { e.shiftKey = true }) - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) triggerEvent(vm.$refs.alt, 'keyup') - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) triggerEvent(vm.$refs.alt, 'keyup', e => { e.altKey = true }) - expect(spy.calls.count()).toBe(3) + expect(spy.mock.calls.length).toBe(3) triggerEvent(vm.$refs.meta, 'keyup') - expect(spy.calls.count()).toBe(3) + expect(spy.mock.calls.length).toBe(3) triggerEvent(vm.$refs.meta, 'keyup', e => { e.metaKey = true }) - expect(spy.calls.count()).toBe(4) + expect(spy.mock.calls.length).toBe(4) }) it('should support exact modifier', () => { @@ -265,19 +265,19 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$refs.ctrl, 'keyup') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$refs.ctrl, 'keyup', e => { e.ctrlKey = true }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) // should not trigger if has other system modifiers triggerEvent(vm.$refs.ctrl, 'keyup', e => { e.ctrlKey = true e.altKey = true }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) }) it('should support system modifiers with exact', () => { @@ -292,19 +292,19 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$refs.ctrl, 'keyup') - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) triggerEvent(vm.$refs.ctrl, 'keyup', e => { e.ctrlKey = true }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) // should not trigger if has other system modifiers triggerEvent(vm.$refs.ctrl, 'keyup', e => { e.ctrlKey = true e.altKey = true }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) }) it('should support number keyCode', () => { @@ -323,9 +323,9 @@ describe('Directive v-on', () => { const left = 0 const middle = 1 const right = 2 - const spyLeft = jasmine.createSpy() - const spyMiddle = jasmine.createSpy() - const spyRight = jasmine.createSpy() + const spyLeft = vi.fn() + const spyMiddle = vi.fn() + const spyRight = vi.fn() vm = new Vue({ el, @@ -378,17 +378,17 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$refs.enter, 'keyup', e => { e.key = 'Enter' }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$refs.space, 'keyup', e => { e.key = ' ' }) - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) triggerEvent(vm.$refs.esc, 'keyup', e => { e.key = 'Escape' }) - expect(spy.calls.count()).toBe(3) + expect(spy.mock.calls.length).toBe(3) triggerEvent(vm.$refs.left, 'keyup', e => { e.key = 'ArrowLeft' }) - expect(spy.calls.count()).toBe(4) + expect(spy.mock.calls.length).toBe(4) triggerEvent(vm.$refs.delete, 'keyup', e => { e.key = 'Backspace' }) - expect(spy.calls.count()).toBe(5) + expect(spy.mock.calls.length).toBe(5) triggerEvent(vm.$refs.delete, 'keyup', e => { e.key = 'Delete' }) - expect(spy.calls.count()).toBe(6) + expect(spy.mock.calls.length).toBe(6) }) it('should support custom keyCode', () => { @@ -471,7 +471,7 @@ describe('Directive v-on', () => { triggerEvent(vm.$el, 'click') expect(`The .native modifier for v-on is only valid on components but it was used on `, @@ -789,18 +789,18 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$el, 'click') - expect(click.calls.count()).toBe(1) - expect(mouseup.calls.count()).toBe(0) + expect(click.mock.calls.length).toBe(1) + expect(mouseup.mock.calls.length).toBe(0) triggerEvent(vm.$el, 'mouseup') - expect(click.calls.count()).toBe(1) - expect(mouseup.calls.count()).toBe(1) + expect(click.mock.calls.length).toBe(1) + expect(mouseup.mock.calls.length).toBe(1) }) it('object syntax (no argument, mixed with normal listeners)', () => { - const click1 = jasmine.createSpy('click1') - const click2 = jasmine.createSpy('click2') - const mouseup = jasmine.createSpy('mouseup') + const click1 = vi.fn() + const click2 = vi.fn() + const mouseup = vi.fn() vm = new Vue({ el, template: ``, @@ -816,20 +816,20 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$el, 'click') - expect(click1.calls.count()).toBe(1) - expect(click2.calls.count()).toBe(1) - expect(mouseup.calls.count()).toBe(0) + expect(click1.mock.calls.length).toBe(1) + expect(click2.mock.calls.length).toBe(1) + expect(mouseup.mock.calls.length).toBe(0) triggerEvent(vm.$el, 'mouseup') - expect(click1.calls.count()).toBe(1) - expect(click2.calls.count()).toBe(1) - expect(mouseup.calls.count()).toBe(1) + expect(click1.mock.calls.length).toBe(1) + expect(click2.mock.calls.length).toBe(1) + expect(mouseup.mock.calls.length).toBe(1) }) it('object syntax (usage in HOC, mixed with native listeners)', () => { - const click = jasmine.createSpy('click') - const mouseup = jasmine.createSpy('mouseup') - const mousedown = jasmine.createSpy('mousedown') + const click = vi.fn() + const mouseup = vi.fn() + const mousedown = vi.fn() vm = new Vue({ el, @@ -855,19 +855,19 @@ describe('Directive v-on', () => { }) triggerEvent(vm.$el, 'click') - expect(click.calls.count()).toBe(1) - expect(mouseup.calls.count()).toBe(0) - expect(mousedown.calls.count()).toBe(0) + expect(click.mock.calls.length).toBe(1) + expect(mouseup.mock.calls.length).toBe(0) + expect(mousedown.mock.calls.length).toBe(0) triggerEvent(vm.$el, 'mouseup') - expect(click.calls.count()).toBe(1) - expect(mouseup.calls.count()).toBe(1) - expect(mousedown.calls.count()).toBe(0) + expect(click.mock.calls.length).toBe(1) + expect(mouseup.mock.calls.length).toBe(1) + expect(mousedown.mock.calls.length).toBe(0) triggerEvent(vm.$el, 'mousedown') - expect(click.calls.count()).toBe(1) - expect(mouseup.calls.count()).toBe(1) - expect(mousedown.calls.count()).toBe(1) + expect(click.mock.calls.length).toBe(1) + expect(mouseup.mock.calls.length).toBe(1) + expect(mousedown.mock.calls.length).toBe(1) }) // #6805 (v-on="object" bind order problem) @@ -948,7 +948,7 @@ describe('Directive v-on', () => { vm.ok = false waitForUpdate(() => { triggerEvent(vm.$el.childNodes[0], 'click') - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) }).then(done) }) @@ -984,12 +984,12 @@ describe('Directive v-on', () => { }) // simulating autocomplete event (Event object with type keyup but without keyCode) triggerEvent(vm.$el, 'keyup') - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) }) describe('dynamic arguments', () => { it('basic', done => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ template: `
`, data: { @@ -1000,25 +1000,25 @@ describe('Directive v-on', () => { } }).$mount() triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) vm.key = 'mouseup' waitForUpdate(() => { triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$el, 'mouseup') - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) // explicit null value vm.key = null }).then(() => { triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) triggerEvent(vm.$el, 'mouseup') - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) }).then(done) }) it('shorthand', done => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ template: `
`, data: { @@ -1029,18 +1029,18 @@ describe('Directive v-on', () => { } }).$mount() triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) vm.key = 'mouseup' waitForUpdate(() => { triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$el, 'mouseup') - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) }).then(done) }) it('with .middle modifier', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ template: `
`, data: { @@ -1057,7 +1057,7 @@ describe('Directive v-on', () => { }) it('with .right modifier', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ template: `
`, data: { @@ -1098,9 +1098,9 @@ describe('Directive v-on', () => { methods: { foo: spy } }).$mount() triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) triggerEvent(vm.$el, 'click') - expect(spy.calls.count()).toBe(1) // should no longer trigger + expect(spy.mock.calls.length).toBe(1) // should no longer trigger }) }) }) diff --git a/test/unit/features/error-handling.spec.ts b/test/unit/features/error-handling.spec.ts index cf838b2fe..ea1903ac7 100644 --- a/test/unit/features/error-handling.spec.ts +++ b/test/unit/features/error-handling.spec.ts @@ -149,7 +149,7 @@ describe('Error handling', () => { }) it('config.errorHandler should capture render errors', done => { - const spy = Vue.config.errorHandler = jasmine.createSpy('errorHandler') + const spy = Vue.config.errorHandler = vi.fn() const vm = createTestInstance(components.render) const args = spy.calls.argsFor(0) @@ -165,7 +165,7 @@ describe('Error handling', () => { it('should capture and recover from nextTick errors', done => { const err1 = new Error('nextTick') const err2 = new Error('nextTick2') - const spy = Vue.config.errorHandler = jasmine.createSpy('errorHandler') + const spy = Vue.config.errorHandler = vi.fn() Vue.nextTick(() => { throw err1 }) Vue.nextTick(() => { expect(spy).toHaveBeenCalledWith(err1, undefined, 'nextTick') diff --git a/test/unit/features/global-api/config.spec.ts b/test/unit/features/global-api/config.spec.ts index f2e5074ce..fb8f45d21 100644 --- a/test/unit/features/global-api/config.spec.ts +++ b/test/unit/features/global-api/config.spec.ts @@ -25,7 +25,7 @@ describe('Global config', () => { describe('optionMergeStrategies', () => { it('should allow defining custom option merging strategies', () => { - const spy = jasmine.createSpy('option merging') + const spy = vi.fn() Vue.config.optionMergeStrategies.__test__ = (parent, child, vm) => { spy(parent, child, vm) return child + 1 @@ -33,13 +33,13 @@ describe('Global config', () => { const Test = Vue.extend({ __test__: 1 }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) expect(spy).toHaveBeenCalledWith(undefined, 1, undefined) expect(Test.options.__test__).toBe(2) const test = new Test({ __test__: 2 }) - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) expect(spy).toHaveBeenCalledWith(2, 2, test) expect(test.$options.__test__).toBe(3) }) @@ -58,7 +58,7 @@ describe('Global config', () => { describe('async', () => { it('does not update synchronously when true', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() const vm = new Vue({ template: `
`, updated: spy, @@ -69,7 +69,7 @@ describe('Global config', () => { }) it('updates synchronously when false', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() Vue.config.async = false const vm = new Vue({ template: `
`, diff --git a/test/unit/features/global-api/mixin.spec.ts b/test/unit/features/global-api/mixin.spec.ts index 503b1ff15..23edf82b4 100644 --- a/test/unit/features/global-api/mixin.spec.ts +++ b/test/unit/features/global-api/mixin.spec.ts @@ -6,7 +6,7 @@ describe('Global API: mixin', () => { afterEach(() => { Vue.options = options }) it('should work', () => { - const spy = jasmine.createSpy('global mixin') + const spy = vi.fn() Vue.mixin({ created () { spy(this.$options.myOption) @@ -87,7 +87,7 @@ describe('Global API: mixin', () => { // #4976 it('should not drop late-attached custom options on existing constructors', () => { - const baseSpy = jasmine.createSpy('base') + const baseSpy = vi.fn() const Base = Vue.extend({ beforeCreate: baseSpy }) @@ -100,11 +100,11 @@ describe('Global API: mixin', () => { $style: () => 123 } - const spy = jasmine.createSpy('late attached') + const spy = vi.fn() Test.options.beforeCreate = Test.options.beforeCreate.concat(spy) // Update super constructor's options - const mixinSpy = jasmine.createSpy('mixin') + const mixinSpy = vi.fn() Vue.mixin({ beforeCreate: mixinSpy }) @@ -114,9 +114,9 @@ describe('Global API: mixin', () => { template: '
{{ $style }}
' }).$mount() - expect(spy.calls.count()).toBe(1) - expect(baseSpy.calls.count()).toBe(1) - expect(mixinSpy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) + expect(baseSpy.mock.calls.length).toBe(1) + expect(mixinSpy.mock.calls.length).toBe(1) expect(vm.$el.textContent).toBe('123') expect(vm.$style).toBe(123) @@ -127,7 +127,7 @@ describe('Global API: mixin', () => { // vue-class-component#83 it('should work for a constructor mixin', () => { - const spy = jasmine.createSpy('global mixin') + const spy = vi.fn() const Mixin = Vue.extend({ created () { spy(this.$options.myOption) @@ -144,13 +144,13 @@ describe('Global API: mixin', () => { // vue-class-component#87 it('should not drop original lifecycle hooks', () => { - const base = jasmine.createSpy('base') + const base = vi.fn() const Base = Vue.extend({ beforeCreate: base }) - const injected = jasmine.createSpy('injected') + const injected = vi.fn() // inject a function Base.options.beforeCreate = Base.options.beforeCreate.concat(injected) @@ -170,7 +170,7 @@ describe('Global API: mixin', () => { // #9198 it('should not mix global mixin lifecycle hook twice', () => { - const spy = jasmine.createSpy('global mixed in lifecycle hook') + const spy = vi.fn() Vue.mixin({ created: spy }) @@ -192,6 +192,6 @@ describe('Global API: mixin', () => { const vm = new Child() expect(typeof vm.$options.methods.a).toBe('function') - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) }) }) diff --git a/test/unit/features/instance/methods-data.spec.ts b/test/unit/features/instance/methods-data.spec.ts index 64050397a..616d5295a 100644 --- a/test/unit/features/instance/methods-data.spec.ts +++ b/test/unit/features/instance/methods-data.spec.ts @@ -21,7 +21,7 @@ describe('Instance methods data', () => { describe('$watch', () => { let vm, spy beforeEach(() => { - spy = jasmine.createSpy('watch') + spy = vi.fn() vm = new Vue({ data: { a: { @@ -41,18 +41,18 @@ describe('Instance methods data', () => { vm.$watch('a.b', spy) vm.a.b = 2 waitForUpdate(() => { - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) expect(spy).toHaveBeenCalledWith(2, 1) vm.a = { b: 3 } }).then(() => { - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) expect(spy).toHaveBeenCalledWith(3, 2) }).then(done) }) it('immediate', () => { vm.$watch('a.b', spy, { immediate: true }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) expect(spy).toHaveBeenCalledWith(1) }) @@ -61,7 +61,7 @@ describe('Instance methods data', () => { unwatch() vm.a.b = 2 waitForUpdate(() => { - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) }).then(done) }) @@ -107,7 +107,7 @@ describe('Instance methods data', () => { handler: 'foo', immediate: true }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) expect(spy).toHaveBeenCalledWith(1) }) @@ -116,7 +116,7 @@ describe('Instance methods data', () => { handler: 'foo', immediate: true }) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) expect(spy).toHaveBeenCalledWith('ok') }) diff --git a/test/unit/features/instance/methods-events.spec.ts b/test/unit/features/instance/methods-events.spec.ts index b35a35cce..09aa52825 100644 --- a/test/unit/features/instance/methods-events.spec.ts +++ b/test/unit/features/instance/methods-events.spec.ts @@ -5,7 +5,7 @@ describe('Instance methods events', () => { beforeEach(() => { // @ts-expect-error const vm = new Vue() - spy = jasmine.createSpy('emitter') + spy = vi.fn() }) it('$on', () => { @@ -15,7 +15,7 @@ describe('Instance methods events', () => { spy.apply(this, arguments) }) vm.$emit('test', 1, 2, 3, 4) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) expect(spy).toHaveBeenCalledWith(1, 2, 3, 4) }) @@ -25,10 +25,10 @@ describe('Instance methods events', () => { spy.apply(this, arguments) }) vm.$emit('test1', 1, 2, 3, 4) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) expect(spy).toHaveBeenCalledWith(1, 2, 3, 4) vm.$emit('test2', 5, 6, 7, 8) - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) expect(spy).toHaveBeenCalledWith(5, 6, 7, 8) }) @@ -39,7 +39,7 @@ describe('Instance methods events', () => { vm.$emit('test2') expect(spy).not.toHaveBeenCalled() vm.$emit('test3', 1, 2, 3, 4) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) }) it('$off multi event without callback', () => { @@ -53,7 +53,7 @@ describe('Instance methods events', () => { vm.$once('test', spy) vm.$emit('test', 1, 2, 3) vm.$emit('test', 2, 3, 4) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) expect(spy).toHaveBeenCalledWith(1, 2, 3) }) @@ -80,18 +80,18 @@ describe('Instance methods events', () => { vm.$off('test1') // test off something that's already off vm.$emit('test1', 1) vm.$emit('test2', 2) - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) expect(spy).toHaveBeenCalledWith(2) }) it('$off event + fn', () => { - const spy2 = jasmine.createSpy('emitter') + const spy2 = vi.fn() vm.$on('test', spy) vm.$on('test', spy2) vm.$off('test', spy) vm.$emit('test', 1, 2, 3) expect(spy).not.toHaveBeenCalled() - expect(spy2.calls.count()).toBe(1) + expect(spy2.mock.calls.length).toBe(1) expect(spy2).toHaveBeenCalledWith(1, 2, 3) }) }) diff --git a/test/unit/features/instance/methods-lifecycle.spec.ts b/test/unit/features/instance/methods-lifecycle.spec.ts index a2c5b86e9..3af73efbb 100644 --- a/test/unit/features/instance/methods-lifecycle.spec.ts +++ b/test/unit/features/instance/methods-lifecycle.spec.ts @@ -57,7 +57,7 @@ describe('Instance methods lifecycle', () => { it('Dep.target should be undefined during invocation of child immediate watcher', done => { let calls = 0 const childData = { a: 1 } - const parentUpdate = jasmine.createSpy() + const parentUpdate = vi.fn() new Vue({ template: '
', updated: parentUpdate, @@ -117,13 +117,13 @@ describe('Instance methods lifecycle', () => { }) it('avoid duplicate calls', () => { - const spy = jasmine.createSpy('destroy') + const spy = vi.fn() const vm = new Vue({ beforeDestroy: spy }) vm.$destroy() vm.$destroy() - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) }) }) diff --git a/test/unit/features/instance/properties.spec.ts b/test/unit/features/instance/properties.spec.ts index 2f06223b6..3e4f36533 100644 --- a/test/unit/features/instance/properties.spec.ts +++ b/test/unit/features/instance/properties.spec.ts @@ -168,8 +168,8 @@ describe('Instance properties', () => { }) it('$listeners', done => { - const spyA = jasmine.createSpy('A') - const spyB = jasmine.createSpy('B') + const spyA = vi.fn() + const spyB = vi.fn() const vm = new Vue({ template: ``, data: { foo: spyA }, @@ -184,14 +184,14 @@ describe('Instance properties', () => { document.body.appendChild(vm.$el) triggerEvent(vm.$el, 'click') - expect(spyA.calls.count()).toBe(1) - expect(spyB.calls.count()).toBe(0) + expect(spyA.mock.calls.length).toBe(1) + expect(spyB.mock.calls.length).toBe(0) vm.foo = spyB waitForUpdate(() => { triggerEvent(vm.$el, 'click') - expect(spyA.calls.count()).toBe(1) - expect(spyB.calls.count()).toBe(1) + expect(spyA.mock.calls.length).toBe(1) + expect(spyB.mock.calls.length).toBe(1) document.body.removeChild(vm.$el) }).then(done) }) diff --git a/test/unit/features/options/computed.spec.ts b/test/unit/features/options/computed.spec.ts index 17cd95166..b2616b138 100644 --- a/test/unit/features/options/computed.spec.ts +++ b/test/unit/features/options/computed.spec.ts @@ -91,7 +91,7 @@ describe('Options computed', () => { }) it('watching computed', done => { - const spy = jasmine.createSpy('watch computed') + const spy = vi.fn() const vm = new Vue({ data: { a: 1 @@ -108,7 +108,7 @@ describe('Options computed', () => { }) it('caching', () => { - const spy = jasmine.createSpy('cached computed') + const spy = vi.fn() const vm = new Vue({ data: { a: 1 @@ -120,15 +120,15 @@ describe('Options computed', () => { } } }) - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) vm.b - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) vm.b - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) }) it('cache: false', () => { - const spy = jasmine.createSpy('cached computed') + const spy = vi.fn() const vm = new Vue({ data: { a: 1 @@ -143,11 +143,11 @@ describe('Options computed', () => { } } }) - expect(spy.calls.count()).toBe(0) + expect(spy.mock.calls.length).toBe(0) vm.b - expect(spy.calls.count()).toBe(1) + expect(spy.mock.calls.length).toBe(1) vm.b - expect(spy.calls.count()).toBe(2) + expect(spy.mock.calls.length).toBe(2) }) it('as component', done => { diff --git a/test/unit/features/options/directives.spec.ts b/test/unit/features/options/directives.spec.ts index f7a69402d..6560e1146 100644 --- a/test/unit/features/options/directives.spec.ts +++ b/test/unit/features/options/directives.spec.ts @@ -2,11 +2,11 @@ import Vue from 'vue' describe('Options directives', () => { it('basic usage', done => { - const bindSpy = jasmine.createSpy('bind') - const insertedSpy = jasmine.createSpy('inserted') - const updateSpy = jasmine.createSpy('update') - const componentUpdatedSpy = jasmine.createSpy('componentUpdated') - const unbindSpy = jasmine.createSpy('unbind') + const bindSpy = vi.fn() + const insertedSpy = vi.fn() + const updateSpy = vi.fn() + const componentUpdatedSpy = vi.fn() + const unbindSpy = vi.fn() const assertContext = (el, binding, vnode) => { expect(vnode.context).toBe(vm) @@ -75,7 +75,7 @@ describe('Options directives', () => { expect(unbindSpy).not.toHaveBeenCalled() vm.msg = 'bye' }).then(() => { - expect(componentUpdatedSpy.calls.count()).toBe(2) + expect(componentUpdatedSpy.mock.calls.length).toBe(2) vm.ok = false }).then(() => { expect(unbindSpy).toHaveBeenCalled() @@ -83,7 +83,7 @@ describe('Options directives', () => { }) it('function shorthand', done => { - const spy = jasmine.createSpy('directive') + const spy = vi.fn() const vm = new Vue({ template: '
', data: { a: 'foo' }, @@ -105,7 +105,7 @@ describe('Options directives', () => { }) it('function shorthand (global)', done => { - const spy = jasmine.createSpy('directive') + const spy = vi.fn() Vue.directive('test', function (el, binding, vnode) { expect(vnode.context).toBe(vm) expect(binding.arg).toBe('arg') @@ -153,7 +153,7 @@ describe('Options directives', () => { it('should properly handle same node with different directive sets', done => { const spies = {} - const createSpy = name => (spies[name] = jasmine.createSpy(name)) + const createSpy = name => (spies[name] = vi.fn()) const vm = new Vue({ data: { ok: true, @@ -183,41 +183,41 @@ describe('Options directives', () => { } }).$mount() - expect(spies.bind1.calls.count()).toBe(2) - expect(spies.inserted1.calls.count()).toBe(2) - expect(spies.bind2.calls.count()).toBe(0) - expect(spies.inserted2.calls.count()).toBe(0) + expect(spies.bind1.mock.calls.length).toBe(2) + expect(spies.inserted1.mock.calls.length).toBe(2) + expect(spies.bind2.mock.calls.length).toBe(0) + expect(spies.inserted2.mock.calls.length).toBe(0) vm.ok = false waitForUpdate(() => { // v-test with modifier should be updated - expect(spies.update1.calls.count()).toBe(1) - expect(spies.componentUpdated1.calls.count()).toBe(1) + expect(spies.update1.mock.calls.length).toBe(1) + expect(spies.componentUpdated1.mock.calls.length).toBe(1) // v-test without modifier should be unbound - expect(spies.unbind1.calls.count()).toBe(1) + expect(spies.unbind1.mock.calls.length).toBe(1) // v-test2 should be bound - expect(spies.bind2.calls.count()).toBe(1) - expect(spies.inserted2.calls.count()).toBe(1) + expect(spies.bind2.mock.calls.length).toBe(1) + expect(spies.inserted2.mock.calls.length).toBe(1) vm.ok = true }).then(() => { // v-test without modifier should be bound again - expect(spies.bind1.calls.count()).toBe(3) - expect(spies.inserted1.calls.count()).toBe(3) + expect(spies.bind1.mock.calls.length).toBe(3) + expect(spies.inserted1.mock.calls.length).toBe(3) // v-test2 should be unbound - expect(spies.unbind2.calls.count()).toBe(1) + expect(spies.unbind2.mock.calls.length).toBe(1) // v-test with modifier should be updated again - expect(spies.update1.calls.count()).toBe(2) - expect(spies.componentUpdated1.calls.count()).toBe(2) + expect(spies.update1.mock.calls.length).toBe(2) + expect(spies.componentUpdated1.mock.calls.length).toBe(2) vm.val = 234 }).then(() => { - expect(spies.update1.calls.count()).toBe(4) - expect(spies.componentUpdated1.calls.count()).toBe(4) + expect(spies.update1.mock.calls.length).toBe(4) + expect(spies.componentUpdated1.mock.calls.length).toBe(4) }).then(done) }) @@ -231,9 +231,9 @@ describe('Options directives', () => { // #6513 it('should invoke unbind & inserted on inner component root element change', done => { const dir = { - bind: jasmine.createSpy('bind'), - inserted: jasmine.createSpy('inserted'), - unbind: jasmine.createSpy('unbind') + bind: vi.fn(), + inserted: vi.fn(), + unbind: vi.fn() } const Child = { @@ -248,20 +248,20 @@ describe('Options directives', () => { }).$mount() const oldEl = vm.$el - expect(dir.bind.calls.count()).toBe(1) + expect(dir.bind.mock.calls.length).toBe(1) expect(dir.bind.calls.argsFor(0)[0]).toBe(oldEl) - expect(dir.inserted.calls.count()).toBe(1) + expect(dir.inserted.mock.calls.length).toBe(1) expect(dir.inserted.calls.argsFor(0)[0]).toBe(oldEl) expect(dir.unbind).not.toHaveBeenCalled() vm.$refs.child.ok = false waitForUpdate(() => { expect(vm.$el.tagName).toBe('SPAN') - expect(dir.bind.calls.count()).toBe(2) + expect(dir.bind.mock.calls.length).toBe(2) expect(dir.bind.calls.argsFor(1)[0]).toBe(vm.$el) - expect(dir.inserted.calls.count()).toBe(2) + expect(dir.inserted.mock.calls.length).toBe(2) expect(dir.inserted.calls.argsFor(1)[0]).toBe(vm.$el) - expect(dir.unbind.calls.count()).toBe(1) + expect(dir.unbind.mock.calls.length).toBe(1) expect(dir.unbind.calls.argsFor(0)[0]).toBe(oldEl) }).then(done) }) diff --git a/test/unit/features/options/errorCaptured.spec.ts b/test/unit/features/options/errorCaptured.spec.ts index bf87144a5..bcda50b6e 100644 --- a/test/unit/features/options/errorCaptured.spec.ts +++ b/test/unit/features/options/errorCaptured.spec.ts @@ -4,7 +4,7 @@ describe('Options errorCaptured', () => { let globalSpy beforeEach(() => { - globalSpy = Vue.config.errorHandler = jasmine.createSpy() + globalSpy = Vue.config.errorHandler = vi.fn() }) afterEach(() => { @@ -12,7 +12,7 @@ describe('Options errorCaptured', () => { }) it('should capture error from child component', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() let child let err @@ -68,7 +68,7 @@ describe('Options errorCaptured', () => { }) it('should not propagate to global handler when returning true', () => { - const spy = jasmine.createSpy() + const spy = vi.fn() let child let err @@ -249,7 +249,7 @@ describe('Options errorCaptured', () => { }) it('should capture error from watcher', done => { - const spy = jasmine.createSpy() + const spy = vi.fn() let child let err @@ -285,7 +285,7 @@ describe('Options errorCaptured', () => { }) it('should capture promise error from watcher', done => { - const spy = jasmine.createSpy() + const spy = vi.fn() let child let err @@ -323,7 +323,7 @@ describe('Options errorCaptured', () => { }) it('should capture error from immediate watcher', done => { - const spy = jasmine.createSpy() + const spy = vi.fn() let child let err @@ -360,7 +360,7 @@ describe('Options errorCaptured', () => { }) it('should capture promise error from immediate watcher', done => { - const spy = jasmine.createSpy() + const spy = vi.fn() let child let err diff --git a/test/unit/features/options/extends.spec.ts b/test/unit/features/options/extends.spec.ts index 173464020..3ea9c4624 100644 --- a/test/unit/features/options/extends.spec.ts +++ b/test/unit/features/options/extends.spec.ts @@ -52,7 +52,7 @@ describe('Options extends', () => { it('should work with global mixins + Object.prototype.watch', done => { Vue.mixin({}) - const spy = jasmine.createSpy('watch') + const spy = vi.fn() const A = Vue.extend({ data: function () { return { a: 1 } diff --git a/test/unit/features/options/functional.spec.ts b/test/unit/features/options/functional.spec.ts index ea85eea8a..eb4c52a7b 100644 --- a/test/unit/features/options/functional.spec.ts +++ b/test/unit/features/options/functional.spec.ts @@ -51,8 +51,8 @@ describe('Options functional', () => { }) it('should expose data.on as listeners', () => { - const foo = jasmine.createSpy('foo') - const bar = jasmine.createSpy('bar') + const foo = vi.fn() + const bar = vi.fn() const vm = new Vue({ template: '
', methods: { foo, bar }, @@ -134,7 +134,7 @@ describe('Options functional', () => { }) it('should let vnode raw data pass through', done => { - const onValid = jasmine.createSpy('valid') + const onValid = vi.fn() const vm = new Vue({ data: { msg: 'hello' }, template: `
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: '
foo
', 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