Skip to content

Commit

Permalink
test: jasmine.createSpy -> vi.fn
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 19, 2022
1 parent 8e672c4 commit 52627b9
Show file tree
Hide file tree
Showing 42 changed files with 469 additions and 469 deletions.
32 changes: 16 additions & 16 deletions test/ssr/ssr-bundle-render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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()
})
})
Expand All @@ -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: {
Expand Down Expand Up @@ -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()
})
})
Expand All @@ -210,19 +210,19 @@ 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'])

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()
Expand All @@ -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: {
Expand Down
100 changes: 50 additions & 50 deletions test/unit/features/component/component-keep-alive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ describe('Component keep-alive', () => {
beforeEach(() => {
one = {
template: '<div>one</div>',
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: '<div>two</div>',
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,
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -651,12 +651,12 @@ describe('Component keep-alive', () => {
const Foo = {
name: 'foo',
template: `<div>foo</div>`,
created: jasmine.createSpy('foo')
created: vi.fn()
}

const Bar = {
template: `<div>bar</div>`,
created: jasmine.createSpy('bar')
created: vi.fn()
}

const Child = {
Expand All @@ -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')
Expand All @@ -703,12 +703,12 @@ describe('Component keep-alive', () => {
it('should cache anonymous components if include is not specified', done => {
const Foo = {
template: `<div>foo</div>`,
created: jasmine.createSpy('foo')
created: vi.fn()
}

const Bar = {
template: `<div>bar</div>`,
created: jasmine.createSpy('bar')
created: vi.fn()
}

const Child = {
Expand All @@ -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')
Expand All @@ -756,7 +756,7 @@ describe('Component keep-alive', () => {
it('should not destroy active instance when pruning cache', done => {
const Foo = {
template: `<div>foo</div>`,
destroyed: jasmine.createSpy('destroyed')
destroyed: vi.fn()
}
const vm = new Vue({
template: `
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 7 additions & 7 deletions test/unit/features/component/component-scoped-slot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
<div>{{ parentCount }}<foo #default>{{ childCount }}</foo></div>
Expand All @@ -923,15 +923,15 @@ describe('Component scoped slot', () => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toMatch(`1<div>0</div>`)
// 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<div>1</div>`)
// 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)
})

Expand Down Expand Up @@ -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: `<div></div>`
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/features/component/component-slot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<test>slot default</test>',
components: {
Expand Down Expand Up @@ -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: `<test><div class="click" @click="test">hi</div></test>`,
methods: {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/directives/for.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<div><test v-for="i in 3"></test></div>`,
components: {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/features/directives/if.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/directives/model-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading

0 comments on commit 52627b9

Please sign in to comment.