mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-03 12:38:24 +08:00
test: jasmine.createSpy -> vi.fn
This commit is contained in:
parent
8e672c4251
commit
52627b95ce
@ -106,8 +106,8 @@ function createAssertions (runInNewContext) {
|
|||||||
|
|
||||||
it('render with cache (get/set)', done => {
|
it('render with cache (get/set)', done => {
|
||||||
const cache = {}
|
const cache = {}
|
||||||
const get = jasmine.createSpy('get')
|
const get = vi.fn()
|
||||||
const set = jasmine.createSpy('set')
|
const set = vi.fn()
|
||||||
const options = {
|
const options = {
|
||||||
runInNewContext,
|
runInNewContext,
|
||||||
cache: {
|
cache: {
|
||||||
@ -138,8 +138,8 @@ function createAssertions (runInNewContext) {
|
|||||||
renderer.renderToString((err, res) => {
|
renderer.renderToString((err, res) => {
|
||||||
expect(err).toBeNull()
|
expect(err).toBeNull()
|
||||||
expect(res).toBe(expected)
|
expect(res).toBe(expected)
|
||||||
expect(get.calls.count()).toBe(2)
|
expect(get.mock.calls.length).toBe(2)
|
||||||
expect(set.calls.count()).toBe(1)
|
expect(set.mock.calls.length).toBe(1)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -148,9 +148,9 @@ function createAssertions (runInNewContext) {
|
|||||||
|
|
||||||
it('render with cache (get/set/has)', done => {
|
it('render with cache (get/set/has)', done => {
|
||||||
const cache = {}
|
const cache = {}
|
||||||
const has = jasmine.createSpy('has')
|
const has = vi.fn()
|
||||||
const get = jasmine.createSpy('get')
|
const get = vi.fn()
|
||||||
const set = jasmine.createSpy('set')
|
const set = vi.fn()
|
||||||
const options = {
|
const options = {
|
||||||
runInNewContext,
|
runInNewContext,
|
||||||
cache: {
|
cache: {
|
||||||
@ -185,9 +185,9 @@ function createAssertions (runInNewContext) {
|
|||||||
renderer.renderToString((err, res) => {
|
renderer.renderToString((err, res) => {
|
||||||
expect(err).toBeNull()
|
expect(err).toBeNull()
|
||||||
expect(res).toBe(expected)
|
expect(res).toBe(expected)
|
||||||
expect(has.calls.count()).toBe(2)
|
expect(has.mock.calls.length).toBe(2)
|
||||||
expect(get.calls.count()).toBe(1)
|
expect(get.mock.calls.length).toBe(1)
|
||||||
expect(set.calls.count()).toBe(1)
|
expect(set.mock.calls.length).toBe(1)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -210,10 +210,10 @@ function createAssertions (runInNewContext) {
|
|||||||
renderer.renderToString(context1, (err, res) => {
|
renderer.renderToString(context1, (err, res) => {
|
||||||
expect(err).toBeNull()
|
expect(err).toBeNull()
|
||||||
expect(res).toBe(expected)
|
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)
|
const cached = cache.get(key)
|
||||||
expect(cached.html).toBe(expected)
|
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
|
// assert component usage registration for nested children
|
||||||
expect(context1.registered).toEqual(['app', 'child', 'grandchild'])
|
expect(context1.registered).toEqual(['app', 'child', 'grandchild'])
|
||||||
@ -221,8 +221,8 @@ function createAssertions (runInNewContext) {
|
|||||||
renderer.renderToString(context2, (err, res) => {
|
renderer.renderToString(context2, (err, res) => {
|
||||||
expect(err).toBeNull()
|
expect(err).toBeNull()
|
||||||
expect(res).toBe(expected)
|
expect(res).toBe(expected)
|
||||||
expect(cache.set.calls.count()).toBe(3) // no new cache sets
|
expect(cache.set.mock.calls.length).toBe(3) // no new cache sets
|
||||||
expect(cache.get.calls.count()).toBe(2) // 1 get for root
|
expect(cache.get.mock.calls.length).toBe(2) // 1 get for root
|
||||||
|
|
||||||
expect(context2.registered).toEqual(['app', 'child', 'grandchild'])
|
expect(context2.registered).toEqual(['app', 'child', 'grandchild'])
|
||||||
done()
|
done()
|
||||||
@ -233,8 +233,8 @@ function createAssertions (runInNewContext) {
|
|||||||
|
|
||||||
it('render with cache (opt-out)', done => {
|
it('render with cache (opt-out)', done => {
|
||||||
const cache = {}
|
const cache = {}
|
||||||
const get = jasmine.createSpy('get')
|
const get = vi.fn()
|
||||||
const set = jasmine.createSpy('set')
|
const set = vi.fn()
|
||||||
const options = {
|
const options = {
|
||||||
runInNewContext,
|
runInNewContext,
|
||||||
cache: {
|
cache: {
|
||||||
|
@ -9,19 +9,19 @@ describe('Component keep-alive', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
one = {
|
one = {
|
||||||
template: '<div>one</div>',
|
template: '<div>one</div>',
|
||||||
created: jasmine.createSpy('one created'),
|
created: vi.fn(),
|
||||||
mounted: jasmine.createSpy('one mounted'),
|
mounted: vi.fn(),
|
||||||
activated: jasmine.createSpy('one activated'),
|
activated: vi.fn(),
|
||||||
deactivated: jasmine.createSpy('one deactivated'),
|
deactivated: vi.fn(),
|
||||||
destroyed: jasmine.createSpy('one destroyed')
|
destroyed: vi.fn()
|
||||||
}
|
}
|
||||||
two = {
|
two = {
|
||||||
template: '<div>two</div>',
|
template: '<div>two</div>',
|
||||||
created: jasmine.createSpy('two created'),
|
created: vi.fn(),
|
||||||
mounted: jasmine.createSpy('two mounted'),
|
mounted: vi.fn(),
|
||||||
activated: jasmine.createSpy('two activated'),
|
activated: vi.fn(),
|
||||||
deactivated: jasmine.createSpy('two deactivated'),
|
deactivated: vi.fn(),
|
||||||
destroyed: jasmine.createSpy('two destroyed')
|
destroyed: vi.fn()
|
||||||
}
|
}
|
||||||
components = {
|
components = {
|
||||||
one,
|
one,
|
||||||
@ -33,11 +33,11 @@ describe('Component keep-alive', () => {
|
|||||||
|
|
||||||
function assertHookCalls (component, callCounts) {
|
function assertHookCalls (component, callCounts) {
|
||||||
expect([
|
expect([
|
||||||
component.created.calls.count(),
|
component.created.mock.calls.length,
|
||||||
component.mounted.calls.count(),
|
component.mounted.mock.calls.length,
|
||||||
component.activated.calls.count(),
|
component.activated.mock.calls.length,
|
||||||
component.deactivated.calls.count(),
|
component.deactivated.mock.calls.length,
|
||||||
component.destroyed.calls.count()
|
component.destroyed.mock.calls.length
|
||||||
]).toEqual(callCounts)
|
]).toEqual(callCounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,21 +507,21 @@ describe('Component keep-alive', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('max', done => {
|
it('max', done => {
|
||||||
const spyA = jasmine.createSpy()
|
const spyA = vi.fn()
|
||||||
const spyB = jasmine.createSpy()
|
const spyB = vi.fn()
|
||||||
const spyC = jasmine.createSpy()
|
const spyC = vi.fn()
|
||||||
const spyAD = jasmine.createSpy()
|
const spyAD = vi.fn()
|
||||||
const spyBD = jasmine.createSpy()
|
const spyBD = vi.fn()
|
||||||
const spyCD = jasmine.createSpy()
|
const spyCD = vi.fn()
|
||||||
|
|
||||||
function assertCount (calls) {
|
function assertCount (calls) {
|
||||||
expect([
|
expect([
|
||||||
spyA.calls.count(),
|
spyA.mock.calls.length,
|
||||||
spyAD.calls.count(),
|
spyAD.mock.calls.length,
|
||||||
spyB.calls.count(),
|
spyB.mock.calls.length,
|
||||||
spyBD.calls.count(),
|
spyBD.mock.calls.length,
|
||||||
spyC.calls.count(),
|
spyC.mock.calls.length,
|
||||||
spyCD.calls.count()
|
spyCD.mock.calls.length
|
||||||
]).toEqual(calls)
|
]).toEqual(calls)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,21 +573,21 @@ describe('Component keep-alive', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('max=1', done => {
|
it('max=1', done => {
|
||||||
const spyA = jasmine.createSpy()
|
const spyA = vi.fn()
|
||||||
const spyB = jasmine.createSpy()
|
const spyB = vi.fn()
|
||||||
const spyC = jasmine.createSpy()
|
const spyC = vi.fn()
|
||||||
const spyAD = jasmine.createSpy()
|
const spyAD = vi.fn()
|
||||||
const spyBD = jasmine.createSpy()
|
const spyBD = vi.fn()
|
||||||
const spyCD = jasmine.createSpy()
|
const spyCD = vi.fn()
|
||||||
|
|
||||||
function assertCount (calls) {
|
function assertCount (calls) {
|
||||||
expect([
|
expect([
|
||||||
spyA.calls.count(),
|
spyA.mock.calls.length,
|
||||||
spyAD.calls.count(),
|
spyAD.mock.calls.length,
|
||||||
spyB.calls.count(),
|
spyB.mock.calls.length,
|
||||||
spyBD.calls.count(),
|
spyBD.mock.calls.length,
|
||||||
spyC.calls.count(),
|
spyC.mock.calls.length,
|
||||||
spyCD.calls.count()
|
spyCD.mock.calls.length
|
||||||
]).toEqual(calls)
|
]).toEqual(calls)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,12 +651,12 @@ describe('Component keep-alive', () => {
|
|||||||
const Foo = {
|
const Foo = {
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
template: `<div>foo</div>`,
|
template: `<div>foo</div>`,
|
||||||
created: jasmine.createSpy('foo')
|
created: vi.fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
const Bar = {
|
const Bar = {
|
||||||
template: `<div>bar</div>`,
|
template: `<div>bar</div>`,
|
||||||
created: jasmine.createSpy('bar')
|
created: vi.fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
const Child = {
|
const Child = {
|
||||||
@ -679,8 +679,8 @@ describe('Component keep-alive', () => {
|
|||||||
}).$mount()
|
}).$mount()
|
||||||
|
|
||||||
function assert (foo, bar) {
|
function assert (foo, bar) {
|
||||||
expect(Foo.created.calls.count()).toBe(foo)
|
expect(Foo.created.mock.calls.length).toBe(foo)
|
||||||
expect(Bar.created.calls.count()).toBe(bar)
|
expect(Bar.created.mock.calls.length).toBe(bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(vm.$el.textContent).toBe('foo')
|
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 => {
|
it('should cache anonymous components if include is not specified', done => {
|
||||||
const Foo = {
|
const Foo = {
|
||||||
template: `<div>foo</div>`,
|
template: `<div>foo</div>`,
|
||||||
created: jasmine.createSpy('foo')
|
created: vi.fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
const Bar = {
|
const Bar = {
|
||||||
template: `<div>bar</div>`,
|
template: `<div>bar</div>`,
|
||||||
created: jasmine.createSpy('bar')
|
created: vi.fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
const Child = {
|
const Child = {
|
||||||
@ -731,8 +731,8 @@ describe('Component keep-alive', () => {
|
|||||||
}).$mount()
|
}).$mount()
|
||||||
|
|
||||||
function assert (foo, bar) {
|
function assert (foo, bar) {
|
||||||
expect(Foo.created.calls.count()).toBe(foo)
|
expect(Foo.created.mock.calls.length).toBe(foo)
|
||||||
expect(Bar.created.calls.count()).toBe(bar)
|
expect(Bar.created.mock.calls.length).toBe(bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(vm.$el.textContent).toBe('foo')
|
expect(vm.$el.textContent).toBe('foo')
|
||||||
@ -756,7 +756,7 @@ describe('Component keep-alive', () => {
|
|||||||
it('should not destroy active instance when pruning cache', done => {
|
it('should not destroy active instance when pruning cache', done => {
|
||||||
const Foo = {
|
const Foo = {
|
||||||
template: `<div>foo</div>`,
|
template: `<div>foo</div>`,
|
||||||
destroyed: jasmine.createSpy('destroyed')
|
destroyed: vi.fn()
|
||||||
}
|
}
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `
|
template: `
|
||||||
@ -1167,7 +1167,7 @@ describe('Component keep-alive', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('async components with transition-mode out-in', done => {
|
it('async components with transition-mode out-in', done => {
|
||||||
const barResolve = jasmine.createSpy('bar resolved')
|
const barResolve = vi.fn()
|
||||||
let next
|
let next
|
||||||
const foo = (resolve) => {
|
const foo = (resolve) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -1231,7 +1231,7 @@ describe('Component keep-alive', () => {
|
|||||||
}).thenWaitFor(_next => { next = _next }).then(() => {
|
}).thenWaitFor(_next => { next = _next }).then(() => {
|
||||||
// foo afterLeave get called
|
// foo afterLeave get called
|
||||||
// and bar has already been resolved before 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('<!---->')
|
expect(vm.$el.innerHTML).toBe('<!---->')
|
||||||
}).thenWaitFor(nextFrame).then(() => {
|
}).thenWaitFor(nextFrame).then(() => {
|
||||||
expect(vm.$el.innerHTML).toBe(
|
expect(vm.$el.innerHTML).toBe(
|
||||||
|
@ -899,8 +899,8 @@ describe('Component scoped slot', () => {
|
|||||||
|
|
||||||
// 2.6 scoped slot perf optimization
|
// 2.6 scoped slot perf optimization
|
||||||
it('should have accurate tracking for scoped slots', done => {
|
it('should have accurate tracking for scoped slots', done => {
|
||||||
const parentUpdate = jasmine.createSpy()
|
const parentUpdate = vi.fn()
|
||||||
const childUpdate = jasmine.createSpy()
|
const childUpdate = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `
|
template: `
|
||||||
<div>{{ parentCount }}<foo #default>{{ childCount }}</foo></div>
|
<div>{{ parentCount }}<foo #default>{{ childCount }}</foo></div>
|
||||||
@ -923,15 +923,15 @@ describe('Component scoped slot', () => {
|
|||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(vm.$el.innerHTML).toMatch(`1<div>0</div>`)
|
expect(vm.$el.innerHTML).toMatch(`1<div>0</div>`)
|
||||||
// should only trigger parent update
|
// should only trigger parent update
|
||||||
expect(parentUpdate.calls.count()).toBe(1)
|
expect(parentUpdate.mock.calls.length).toBe(1)
|
||||||
expect(childUpdate.calls.count()).toBe(0)
|
expect(childUpdate.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
vm.childCount++
|
vm.childCount++
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(vm.$el.innerHTML).toMatch(`1<div>1</div>`)
|
expect(vm.$el.innerHTML).toMatch(`1<div>1</div>`)
|
||||||
// should only trigger child update
|
// should only trigger child update
|
||||||
expect(parentUpdate.calls.count()).toBe(1)
|
expect(parentUpdate.mock.calls.length).toBe(1)
|
||||||
expect(childUpdate.calls.count()).toBe(1)
|
expect(childUpdate.mock.calls.length).toBe(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -972,7 +972,7 @@ describe('Component scoped slot', () => {
|
|||||||
// regression #9396
|
// regression #9396
|
||||||
it('should not force update child with no slot content', done => {
|
it('should not force update child with no slot content', done => {
|
||||||
const Child = {
|
const Child = {
|
||||||
updated: jasmine.createSpy(),
|
updated: vi.fn(),
|
||||||
template: `<div></div>`
|
template: `<div></div>`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ describe('Component slot', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('fallback content should not be evaluated when the parent is providing it', () => {
|
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({
|
const vm = new Vue({
|
||||||
template: '<test>slot default</test>',
|
template: '<test>slot default</test>',
|
||||||
components: {
|
components: {
|
||||||
@ -567,7 +567,7 @@ describe('Component slot', () => {
|
|||||||
|
|
||||||
// #3518
|
// #3518
|
||||||
it('events should not break when slot is toggled by v-if', done => {
|
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({
|
const vm = new Vue({
|
||||||
template: `<test><div class="click" @click="test">hi</div></test>`,
|
template: `<test><div class="click" @click="test">hi</div></test>`,
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -360,7 +360,7 @@ describe('Component', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('catch component render error and preserve previous vnode', done => {
|
it('catch component render error and preserve previous vnode', done => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
Vue.config.errorHandler = spy
|
Vue.config.errorHandler = spy
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
|
@ -88,7 +88,7 @@ found in
|
|||||||
const vm = new Vue()
|
const vm = new Vue()
|
||||||
|
|
||||||
it('calls warnHandler if warnHandler is set', () => {
|
it('calls warnHandler if warnHandler is set', () => {
|
||||||
Vue.config.warnHandler = jasmine.createSpy()
|
Vue.config.warnHandler = vi.fn()
|
||||||
|
|
||||||
warn(msg, vm)
|
warn(msg, vm)
|
||||||
|
|
||||||
|
@ -627,7 +627,7 @@ describe('Directive v-for', () => {
|
|||||||
|
|
||||||
it('should warn component v-for without keys', () => {
|
it('should warn component v-for without keys', () => {
|
||||||
const warn = console.warn
|
const warn = console.warn
|
||||||
console.warn = jasmine.createSpy()
|
console.warn = vi.fn()
|
||||||
new Vue({
|
new Vue({
|
||||||
template: `<div><test v-for="i in 3"></test></div>`,
|
template: `<div><test v-for="i in 3"></test></div>`,
|
||||||
components: {
|
components: {
|
||||||
|
@ -243,8 +243,8 @@ describe('Directive v-if', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should maintain stable list to avoid unnecessary patches', done => {
|
it('should maintain stable list to avoid unnecessary patches', done => {
|
||||||
const created = jasmine.createSpy()
|
const created = vi.fn()
|
||||||
const destroyed = jasmine.createSpy()
|
const destroyed = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
ok: true
|
ok: true
|
||||||
@ -266,10 +266,10 @@ describe('Directive v-if', () => {
|
|||||||
}
|
}
|
||||||
}).$mount()
|
}).$mount()
|
||||||
|
|
||||||
expect(created.calls.count()).toBe(1)
|
expect(created.mock.calls.length).toBe(1)
|
||||||
vm.ok = false
|
vm.ok = false
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(created.calls.count()).toBe(1)
|
expect(created.mock.calls.length).toBe(1)
|
||||||
expect(destroyed).not.toHaveBeenCalled()
|
expect(destroyed).not.toHaveBeenCalled()
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
@ -72,7 +72,7 @@ describe('Directive v-model component', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should support customization via model option', done => {
|
it('should support customization via model option', done => {
|
||||||
const spy = jasmine.createSpy('update')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
msg: 'hello'
|
msg: 'hello'
|
||||||
|
@ -86,7 +86,7 @@ describe('Directive v-model radio', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('multiple radios ', (done) => {
|
it('multiple radios ', (done) => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
selections: ['a', '1'],
|
selections: ['a', '1'],
|
||||||
|
@ -207,7 +207,7 @@ describe('Directive v-model select', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should work with select which has no default selected options', (done) => {
|
it('should work with select which has no default selected options', (done) => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
id: 4,
|
id: 4,
|
||||||
@ -228,7 +228,7 @@ describe('Directive v-model select', () => {
|
|||||||
document.body.appendChild(vm.$el)
|
document.body.appendChild(vm.$el)
|
||||||
vm.testChange = 10
|
vm.testChange = 10
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ describe('Directive v-model select', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('should work with multiple binding', (done) => {
|
it('should work with multiple binding', (done) => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
isMultiple: true,
|
isMultiple: true,
|
||||||
@ -352,7 +352,7 @@ describe('Directive v-model select', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('multiple selects', (done) => {
|
it('multiple selects', (done) => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
selections: ['', ''],
|
selections: ['', ''],
|
||||||
@ -520,7 +520,7 @@ describe('Directive v-model select', () => {
|
|||||||
|
|
||||||
// #6193
|
// #6193
|
||||||
it('should not trigger change event when matching option can be found for each value', done => {
|
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({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
options: ['1']
|
options: ['1']
|
||||||
|
@ -136,7 +136,7 @@ describe('Directive v-model text', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('multiple inputs', (done) => {
|
it('multiple inputs', (done) => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
selections: [[1, 2, 3], [4, 5]],
|
selections: [[1, 2, 3], [4, 5]],
|
||||||
@ -230,7 +230,7 @@ describe('Directive v-model text', () => {
|
|||||||
|
|
||||||
// #3468
|
// #3468
|
||||||
it('should have higher priority than user v-on events', () => {
|
it('should have higher priority than user v-on events', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
a: 'a'
|
a: 'a'
|
||||||
@ -317,7 +317,7 @@ describe('Directive v-model text', () => {
|
|||||||
|
|
||||||
if (!isAndroid) {
|
if (!isAndroid) {
|
||||||
it('does not trigger extra input events with single compositionend', () => {
|
it('does not trigger extra input events with single compositionend', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
a: 'a'
|
a: 'a'
|
||||||
@ -329,16 +329,16 @@ describe('Directive v-model text', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).$mount()
|
}).$mount()
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
vm.$el.value = 'b'
|
vm.$el.value = 'b'
|
||||||
triggerEvent(vm.$el, 'input')
|
triggerEvent(vm.$el, 'input')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$el, 'compositionend')
|
triggerEvent(vm.$el, 'compositionend')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('triggers extra input on compositionstart + end', () => {
|
it('triggers extra input on compositionstart + end', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
a: 'a'
|
a: 'a'
|
||||||
@ -350,13 +350,13 @@ describe('Directive v-model text', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).$mount()
|
}).$mount()
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
vm.$el.value = 'b'
|
vm.$el.value = 'b'
|
||||||
triggerEvent(vm.$el, 'input')
|
triggerEvent(vm.$el, 'input')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$el, 'compositionstart')
|
triggerEvent(vm.$el, 'compositionstart')
|
||||||
triggerEvent(vm.$el, 'compositionend')
|
triggerEvent(vm.$el, 'compositionend')
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
// #4392
|
// #4392
|
||||||
|
@ -6,7 +6,7 @@ describe('Directive v-on', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vm = null
|
vm = null
|
||||||
spy = jasmine.createSpy()
|
spy = vi.fn()
|
||||||
el = document.createElement('div')
|
el = document.createElement('div')
|
||||||
document.body.appendChild(el)
|
document.body.appendChild(el)
|
||||||
})
|
})
|
||||||
@ -24,7 +24,7 @@ describe('Directive v-on', () => {
|
|||||||
methods: { foo: spy }
|
methods: { foo: spy }
|
||||||
})
|
})
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
const args = spy.calls.allArgs()
|
const args = spy.calls.allArgs()
|
||||||
const event = args[0] && args[0][0] || {}
|
const event = args[0] && args[0][0] || {}
|
||||||
@ -38,7 +38,7 @@ describe('Directive v-on', () => {
|
|||||||
methods: { foo: spy }
|
methods: { foo: spy }
|
||||||
})
|
})
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
const args = spy.calls.allArgs()
|
const args = spy.calls.allArgs()
|
||||||
const firstArgs = args[0]
|
const firstArgs = args[0]
|
||||||
@ -50,7 +50,7 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should support inline function expression', () => {
|
it('should support inline function expression', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
template: `<div class="test" @click="function (e) { log(e.target.className) }"></div>`,
|
template: `<div class="test" @click="function (e) { log(e.target.className) }"></div>`,
|
||||||
@ -69,7 +69,7 @@ describe('Directive v-on', () => {
|
|||||||
methods: { foo: spy }
|
methods: { foo: spy }
|
||||||
})
|
})
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support stop propagation', () => {
|
it('should support stop propagation', () => {
|
||||||
@ -130,9 +130,9 @@ describe('Directive v-on', () => {
|
|||||||
methods: { foo: spy }
|
methods: { foo: spy }
|
||||||
})
|
})
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$el, 'click')
|
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
|
// #4655
|
||||||
@ -148,14 +148,14 @@ describe('Directive v-on', () => {
|
|||||||
methods: { foo: spy }
|
methods: { foo: spy }
|
||||||
})
|
})
|
||||||
triggerEvent(vm.$refs.one, 'click')
|
triggerEvent(vm.$refs.one, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$refs.one, 'click')
|
triggerEvent(vm.$refs.one, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$refs.two, 'click')
|
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.one, 'click')
|
||||||
triggerEvent(vm.$refs.two, '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', () => {
|
it('should support capture and once', () => {
|
||||||
@ -190,7 +190,7 @@ describe('Directive v-on', () => {
|
|||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy).toHaveBeenCalled()
|
expect(spy).toHaveBeenCalled()
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support keyCode', () => {
|
it('should support keyCode', () => {
|
||||||
@ -233,24 +233,24 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
triggerEvent(vm.$refs.ctrl, 'keyup')
|
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 })
|
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')
|
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 })
|
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')
|
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 })
|
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')
|
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 })
|
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', () => {
|
it('should support exact modifier', () => {
|
||||||
@ -265,19 +265,19 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
triggerEvent(vm.$refs.ctrl, 'keyup')
|
triggerEvent(vm.$refs.ctrl, 'keyup')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
triggerEvent(vm.$refs.ctrl, 'keyup', e => {
|
triggerEvent(vm.$refs.ctrl, 'keyup', e => {
|
||||||
e.ctrlKey = true
|
e.ctrlKey = true
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
// should not trigger if has other system modifiers
|
// should not trigger if has other system modifiers
|
||||||
triggerEvent(vm.$refs.ctrl, 'keyup', e => {
|
triggerEvent(vm.$refs.ctrl, 'keyup', e => {
|
||||||
e.ctrlKey = true
|
e.ctrlKey = true
|
||||||
e.altKey = true
|
e.altKey = true
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support system modifiers with exact', () => {
|
it('should support system modifiers with exact', () => {
|
||||||
@ -292,19 +292,19 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
triggerEvent(vm.$refs.ctrl, 'keyup')
|
triggerEvent(vm.$refs.ctrl, 'keyup')
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
triggerEvent(vm.$refs.ctrl, 'keyup', e => {
|
triggerEvent(vm.$refs.ctrl, 'keyup', e => {
|
||||||
e.ctrlKey = true
|
e.ctrlKey = true
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
// should not trigger if has other system modifiers
|
// should not trigger if has other system modifiers
|
||||||
triggerEvent(vm.$refs.ctrl, 'keyup', e => {
|
triggerEvent(vm.$refs.ctrl, 'keyup', e => {
|
||||||
e.ctrlKey = true
|
e.ctrlKey = true
|
||||||
e.altKey = true
|
e.altKey = true
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support number keyCode', () => {
|
it('should support number keyCode', () => {
|
||||||
@ -323,9 +323,9 @@ describe('Directive v-on', () => {
|
|||||||
const left = 0
|
const left = 0
|
||||||
const middle = 1
|
const middle = 1
|
||||||
const right = 2
|
const right = 2
|
||||||
const spyLeft = jasmine.createSpy()
|
const spyLeft = vi.fn()
|
||||||
const spyMiddle = jasmine.createSpy()
|
const spyMiddle = vi.fn()
|
||||||
const spyRight = jasmine.createSpy()
|
const spyRight = vi.fn()
|
||||||
|
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
@ -378,17 +378,17 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
triggerEvent(vm.$refs.enter, 'keyup', e => { e.key = 'Enter' })
|
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 = ' ' })
|
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' })
|
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' })
|
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' })
|
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' })
|
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', () => {
|
it('should support custom keyCode', () => {
|
||||||
@ -471,7 +471,7 @@ describe('Directive v-on', () => {
|
|||||||
|
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(`The .native modifier for v-on is only valid on components but it was used on <button>.`).toHaveBeenWarned()
|
expect(`The .native modifier for v-on is only valid on components but it was used on <button>.`).toHaveBeenWarned()
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not throw a warning if native modifier is used on a dynamic component', () => {
|
it('should not throw a warning if native modifier is used on a dynamic component', () => {
|
||||||
@ -500,13 +500,13 @@ describe('Directive v-on', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
vm.$children[0].$emit('custom')
|
vm.$children[0].$emit('custom')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
vm.$children[0].$emit('custom')
|
vm.$children[0].$emit('custom')
|
||||||
expect(spy.calls.count()).toBe(1) // should not be called again
|
expect(spy.mock.calls.length).toBe(1) // should not be called again
|
||||||
})
|
})
|
||||||
|
|
||||||
it('remove listener', done => {
|
it('remove listener', done => {
|
||||||
const spy2 = jasmine.createSpy('remove listener')
|
const spy2 = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
methods: { foo: spy, bar: spy2 },
|
methods: { foo: spy, bar: spy2 },
|
||||||
@ -520,19 +520,19 @@ describe('Directive v-on', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy2.calls.count()).toBe(0)
|
expect(spy2.mock.calls.length).toBe(0)
|
||||||
vm.ok = false
|
vm.ok = false
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
triggerEvent(vm.$el, 'click')
|
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
|
||||||
triggerEvent(vm.$el, 'input')
|
triggerEvent(vm.$el, 'input')
|
||||||
expect(spy2.calls.count()).toBe(1)
|
expect(spy2.mock.calls.length).toBe(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('remove capturing listener', done => {
|
it('remove capturing listener', done => {
|
||||||
const spy2 = jasmine.createSpy('remove listener')
|
const spy2 = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
methods: { foo: spy, bar: spy2, stopped (ev) { ev.stopPropagation() } },
|
methods: { foo: spy, bar: spy2, stopped (ev) { ev.stopPropagation() } },
|
||||||
@ -546,19 +546,19 @@ describe('Directive v-on', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
triggerEvent(vm.$el.firstChild, 'click')
|
triggerEvent(vm.$el.firstChild, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy2.calls.count()).toBe(0)
|
expect(spy2.mock.calls.length).toBe(0)
|
||||||
vm.ok = false
|
vm.ok = false
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
triggerEvent(vm.$el.firstChild, 'click')
|
triggerEvent(vm.$el.firstChild, 'click')
|
||||||
expect(spy.calls.count()).toBe(1) // should no longer trigger
|
expect(spy.mock.calls.length).toBe(1) // should no longer trigger
|
||||||
triggerEvent(vm.$el, 'mouseOver')
|
triggerEvent(vm.$el, 'mouseOver')
|
||||||
expect(spy2.calls.count()).toBe(1)
|
expect(spy2.mock.calls.length).toBe(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('remove once listener', done => {
|
it('remove once listener', done => {
|
||||||
const spy2 = jasmine.createSpy('remove listener')
|
const spy2 = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
methods: { foo: spy, bar: spy2 },
|
methods: { foo: spy, bar: spy2 },
|
||||||
@ -572,21 +572,21 @@ describe('Directive v-on', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$el, 'click')
|
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
|
||||||
expect(spy2.calls.count()).toBe(0)
|
expect(spy2.mock.calls.length).toBe(0)
|
||||||
vm.ok = false
|
vm.ok = false
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
triggerEvent(vm.$el, 'click')
|
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
|
||||||
triggerEvent(vm.$el, 'input')
|
triggerEvent(vm.$el, 'input')
|
||||||
expect(spy2.calls.count()).toBe(1)
|
expect(spy2.mock.calls.length).toBe(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('remove capturing and once listener', done => {
|
it('remove capturing and once listener', done => {
|
||||||
const spy2 = jasmine.createSpy('remove listener')
|
const spy2 = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
methods: { foo: spy, bar: spy2, stopped (ev) { ev.stopPropagation() } },
|
methods: { foo: spy, bar: spy2, stopped (ev) { ev.stopPropagation() } },
|
||||||
@ -600,21 +600,21 @@ describe('Directive v-on', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
triggerEvent(vm.$el.firstChild, 'click')
|
triggerEvent(vm.$el.firstChild, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$el.firstChild, 'click')
|
triggerEvent(vm.$el.firstChild, 'click')
|
||||||
expect(spy.calls.count()).toBe(1) // should no longer trigger
|
expect(spy.mock.calls.length).toBe(1) // should no longer trigger
|
||||||
expect(spy2.calls.count()).toBe(0)
|
expect(spy2.mock.calls.length).toBe(0)
|
||||||
vm.ok = false
|
vm.ok = false
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
triggerEvent(vm.$el.firstChild, 'click')
|
triggerEvent(vm.$el.firstChild, 'click')
|
||||||
expect(spy.calls.count()).toBe(1) // should no longer trigger
|
expect(spy.mock.calls.length).toBe(1) // should no longer trigger
|
||||||
triggerEvent(vm.$el, 'mouseOver')
|
triggerEvent(vm.$el, 'mouseOver')
|
||||||
expect(spy2.calls.count()).toBe(1)
|
expect(spy2.mock.calls.length).toBe(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('remove listener on child component', done => {
|
it('remove listener on child component', done => {
|
||||||
const spy2 = jasmine.createSpy('remove listener')
|
const spy2 = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
methods: { foo: spy, bar: spy2 },
|
methods: { foo: spy, bar: spy2 },
|
||||||
@ -633,14 +633,14 @@ describe('Directive v-on', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
vm.$children[0].$emit('foo')
|
vm.$children[0].$emit('foo')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy2.calls.count()).toBe(0)
|
expect(spy2.mock.calls.length).toBe(0)
|
||||||
vm.ok = false
|
vm.ok = false
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
vm.$children[0].$emit('foo')
|
vm.$children[0].$emit('foo')
|
||||||
expect(spy.calls.count()).toBe(1) // should no longer trigger
|
expect(spy.mock.calls.length).toBe(1) // should no longer trigger
|
||||||
vm.$children[0].$emit('bar')
|
vm.$children[0].$emit('bar')
|
||||||
expect(spy2.calls.count()).toBe(1)
|
expect(spy2.mock.calls.length).toBe(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -658,10 +658,10 @@ describe('Directive v-on', () => {
|
|||||||
|
|
||||||
// Github Issue #5046
|
// Github Issue #5046
|
||||||
it('should support keyboard modifier for direction keys', () => {
|
it('should support keyboard modifier for direction keys', () => {
|
||||||
const spyLeft = jasmine.createSpy()
|
const spyLeft = vi.fn()
|
||||||
const spyRight = jasmine.createSpy()
|
const spyRight = vi.fn()
|
||||||
const spyUp = jasmine.createSpy()
|
const spyUp = vi.fn()
|
||||||
const spyDown = jasmine.createSpy()
|
const spyDown = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
template: `
|
template: `
|
||||||
@ -691,10 +691,10 @@ describe('Directive v-on', () => {
|
|||||||
triggerEvent(vm.$refs.down, 'keydown', e => { e.keyCode = 40 })
|
triggerEvent(vm.$refs.down, 'keydown', e => { e.keyCode = 40 })
|
||||||
triggerEvent(vm.$refs.down, 'keydown', e => { e.keyCode = 39 })
|
triggerEvent(vm.$refs.down, 'keydown', e => { e.keyCode = 39 })
|
||||||
|
|
||||||
expect(spyLeft.calls.count()).toBe(1)
|
expect(spyLeft.mock.calls.length).toBe(1)
|
||||||
expect(spyRight.calls.count()).toBe(1)
|
expect(spyRight.mock.calls.length).toBe(1)
|
||||||
expect(spyUp.calls.count()).toBe(1)
|
expect(spyUp.mock.calls.length).toBe(1)
|
||||||
expect(spyDown.calls.count()).toBe(1)
|
expect(spyDown.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
// This test case should only run when the test browser supports passive.
|
// This test case should only run when the test browser supports passive.
|
||||||
@ -751,7 +751,7 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should transform click.right to contextmenu', () => {
|
it('should transform click.right to contextmenu', () => {
|
||||||
const spy = jasmine.createSpy('click.right')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<div @click.right="foo"></div>`,
|
template: `<div @click.right="foo"></div>`,
|
||||||
methods: { foo: spy }
|
methods: { foo: spy }
|
||||||
@ -762,7 +762,7 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should transform click.middle to mouseup', () => {
|
it('should transform click.middle to mouseup', () => {
|
||||||
const spy = jasmine.createSpy('click.middle')
|
const spy = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
template: `<div @click.middle="foo"></div>`,
|
template: `<div @click.middle="foo"></div>`,
|
||||||
@ -775,8 +775,8 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('object syntax (no argument)', () => {
|
it('object syntax (no argument)', () => {
|
||||||
const click = jasmine.createSpy('click')
|
const click = vi.fn()
|
||||||
const mouseup = jasmine.createSpy('mouseup')
|
const mouseup = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
template: `<button v-on="listeners">foo</button>`,
|
template: `<button v-on="listeners">foo</button>`,
|
||||||
@ -789,18 +789,18 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
expect(mouseup.calls.count()).toBe(0)
|
expect(mouseup.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
triggerEvent(vm.$el, 'mouseup')
|
triggerEvent(vm.$el, 'mouseup')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
expect(mouseup.calls.count()).toBe(1)
|
expect(mouseup.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('object syntax (no argument, mixed with normal listeners)', () => {
|
it('object syntax (no argument, mixed with normal listeners)', () => {
|
||||||
const click1 = jasmine.createSpy('click1')
|
const click1 = vi.fn()
|
||||||
const click2 = jasmine.createSpy('click2')
|
const click2 = vi.fn()
|
||||||
const mouseup = jasmine.createSpy('mouseup')
|
const mouseup = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
template: `<button v-on="listeners" @click="click2">foo</button>`,
|
template: `<button v-on="listeners" @click="click2">foo</button>`,
|
||||||
@ -816,20 +816,20 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(click1.calls.count()).toBe(1)
|
expect(click1.mock.calls.length).toBe(1)
|
||||||
expect(click2.calls.count()).toBe(1)
|
expect(click2.mock.calls.length).toBe(1)
|
||||||
expect(mouseup.calls.count()).toBe(0)
|
expect(mouseup.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
triggerEvent(vm.$el, 'mouseup')
|
triggerEvent(vm.$el, 'mouseup')
|
||||||
expect(click1.calls.count()).toBe(1)
|
expect(click1.mock.calls.length).toBe(1)
|
||||||
expect(click2.calls.count()).toBe(1)
|
expect(click2.mock.calls.length).toBe(1)
|
||||||
expect(mouseup.calls.count()).toBe(1)
|
expect(mouseup.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('object syntax (usage in HOC, mixed with native listeners)', () => {
|
it('object syntax (usage in HOC, mixed with native listeners)', () => {
|
||||||
const click = jasmine.createSpy('click')
|
const click = vi.fn()
|
||||||
const mouseup = jasmine.createSpy('mouseup')
|
const mouseup = vi.fn()
|
||||||
const mousedown = jasmine.createSpy('mousedown')
|
const mousedown = vi.fn()
|
||||||
|
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
el,
|
el,
|
||||||
@ -855,19 +855,19 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
expect(mouseup.calls.count()).toBe(0)
|
expect(mouseup.mock.calls.length).toBe(0)
|
||||||
expect(mousedown.calls.count()).toBe(0)
|
expect(mousedown.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
triggerEvent(vm.$el, 'mouseup')
|
triggerEvent(vm.$el, 'mouseup')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
expect(mouseup.calls.count()).toBe(1)
|
expect(mouseup.mock.calls.length).toBe(1)
|
||||||
expect(mousedown.calls.count()).toBe(0)
|
expect(mousedown.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
triggerEvent(vm.$el, 'mousedown')
|
triggerEvent(vm.$el, 'mousedown')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
expect(mouseup.calls.count()).toBe(1)
|
expect(mouseup.mock.calls.length).toBe(1)
|
||||||
expect(mousedown.calls.count()).toBe(1)
|
expect(mousedown.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
// #6805 (v-on="object" bind order problem)
|
// #6805 (v-on="object" bind order problem)
|
||||||
@ -948,7 +948,7 @@ describe('Directive v-on', () => {
|
|||||||
vm.ok = false
|
vm.ok = false
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
triggerEvent(vm.$el.childNodes[0], 'click')
|
triggerEvent(vm.$el.childNodes[0], 'click')
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -984,12 +984,12 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
// simulating autocomplete event (Event object with type keyup but without keyCode)
|
// simulating autocomplete event (Event object with type keyup but without keyCode)
|
||||||
triggerEvent(vm.$el, 'keyup')
|
triggerEvent(vm.$el, 'keyup')
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('dynamic arguments', () => {
|
describe('dynamic arguments', () => {
|
||||||
it('basic', done => {
|
it('basic', done => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<div v-on:[key]="spy"></div>`,
|
template: `<div v-on:[key]="spy"></div>`,
|
||||||
data: {
|
data: {
|
||||||
@ -1000,25 +1000,25 @@ describe('Directive v-on', () => {
|
|||||||
}
|
}
|
||||||
}).$mount()
|
}).$mount()
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
vm.key = 'mouseup'
|
vm.key = 'mouseup'
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$el, 'mouseup')
|
triggerEvent(vm.$el, 'mouseup')
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
// explicit null value
|
// explicit null value
|
||||||
vm.key = null
|
vm.key = null
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
triggerEvent(vm.$el, 'mouseup')
|
triggerEvent(vm.$el, 'mouseup')
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shorthand', done => {
|
it('shorthand', done => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<div @[key]="spy"></div>`,
|
template: `<div @[key]="spy"></div>`,
|
||||||
data: {
|
data: {
|
||||||
@ -1029,18 +1029,18 @@ describe('Directive v-on', () => {
|
|||||||
}
|
}
|
||||||
}).$mount()
|
}).$mount()
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
vm.key = 'mouseup'
|
vm.key = 'mouseup'
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$el, 'mouseup')
|
triggerEvent(vm.$el, 'mouseup')
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('with .middle modifier', () => {
|
it('with .middle modifier', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<div @[key].middle="spy"></div>`,
|
template: `<div @[key].middle="spy"></div>`,
|
||||||
data: {
|
data: {
|
||||||
@ -1057,7 +1057,7 @@ describe('Directive v-on', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('with .right modifier', () => {
|
it('with .right modifier', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<div @[key].right="spy"></div>`,
|
template: `<div @[key].right="spy"></div>`,
|
||||||
data: {
|
data: {
|
||||||
@ -1098,9 +1098,9 @@ describe('Directive v-on', () => {
|
|||||||
methods: { foo: spy }
|
methods: { foo: spy }
|
||||||
}).$mount()
|
}).$mount()
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
triggerEvent(vm.$el, 'click')
|
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
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -149,7 +149,7 @@ describe('Error handling', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('config.errorHandler should capture render errors', done => {
|
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 vm = createTestInstance(components.render)
|
||||||
|
|
||||||
const args = spy.calls.argsFor(0)
|
const args = spy.calls.argsFor(0)
|
||||||
@ -165,7 +165,7 @@ describe('Error handling', () => {
|
|||||||
it('should capture and recover from nextTick errors', done => {
|
it('should capture and recover from nextTick errors', done => {
|
||||||
const err1 = new Error('nextTick')
|
const err1 = new Error('nextTick')
|
||||||
const err2 = new Error('nextTick2')
|
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(() => { throw err1 })
|
||||||
Vue.nextTick(() => {
|
Vue.nextTick(() => {
|
||||||
expect(spy).toHaveBeenCalledWith(err1, undefined, 'nextTick')
|
expect(spy).toHaveBeenCalledWith(err1, undefined, 'nextTick')
|
||||||
|
@ -25,7 +25,7 @@ describe('Global config', () => {
|
|||||||
|
|
||||||
describe('optionMergeStrategies', () => {
|
describe('optionMergeStrategies', () => {
|
||||||
it('should allow defining custom option merging strategies', () => {
|
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) => {
|
Vue.config.optionMergeStrategies.__test__ = (parent, child, vm) => {
|
||||||
spy(parent, child, vm)
|
spy(parent, child, vm)
|
||||||
return child + 1
|
return child + 1
|
||||||
@ -33,13 +33,13 @@ describe('Global config', () => {
|
|||||||
const Test = Vue.extend({
|
const Test = Vue.extend({
|
||||||
__test__: 1
|
__test__: 1
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy).toHaveBeenCalledWith(undefined, 1, undefined)
|
expect(spy).toHaveBeenCalledWith(undefined, 1, undefined)
|
||||||
expect(Test.options.__test__).toBe(2)
|
expect(Test.options.__test__).toBe(2)
|
||||||
const test = new Test({
|
const test = new Test({
|
||||||
__test__: 2
|
__test__: 2
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
expect(spy).toHaveBeenCalledWith(2, 2, test)
|
expect(spy).toHaveBeenCalledWith(2, 2, test)
|
||||||
expect(test.$options.__test__).toBe(3)
|
expect(test.$options.__test__).toBe(3)
|
||||||
})
|
})
|
||||||
@ -58,7 +58,7 @@ describe('Global config', () => {
|
|||||||
|
|
||||||
describe('async', () => {
|
describe('async', () => {
|
||||||
it('does not update synchronously when true', () => {
|
it('does not update synchronously when true', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<div :class="value"></div>`,
|
template: `<div :class="value"></div>`,
|
||||||
updated: spy,
|
updated: spy,
|
||||||
@ -69,7 +69,7 @@ describe('Global config', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('updates synchronously when false', () => {
|
it('updates synchronously when false', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
Vue.config.async = false
|
Vue.config.async = false
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<div :class="value"></div>`,
|
template: `<div :class="value"></div>`,
|
||||||
|
@ -6,7 +6,7 @@ describe('Global API: mixin', () => {
|
|||||||
afterEach(() => { Vue.options = options })
|
afterEach(() => { Vue.options = options })
|
||||||
|
|
||||||
it('should work', () => {
|
it('should work', () => {
|
||||||
const spy = jasmine.createSpy('global mixin')
|
const spy = vi.fn()
|
||||||
Vue.mixin({
|
Vue.mixin({
|
||||||
created () {
|
created () {
|
||||||
spy(this.$options.myOption)
|
spy(this.$options.myOption)
|
||||||
@ -87,7 +87,7 @@ describe('Global API: mixin', () => {
|
|||||||
|
|
||||||
// #4976
|
// #4976
|
||||||
it('should not drop late-attached custom options on existing constructors', () => {
|
it('should not drop late-attached custom options on existing constructors', () => {
|
||||||
const baseSpy = jasmine.createSpy('base')
|
const baseSpy = vi.fn()
|
||||||
const Base = Vue.extend({
|
const Base = Vue.extend({
|
||||||
beforeCreate: baseSpy
|
beforeCreate: baseSpy
|
||||||
})
|
})
|
||||||
@ -100,11 +100,11 @@ describe('Global API: mixin', () => {
|
|||||||
$style: () => 123
|
$style: () => 123
|
||||||
}
|
}
|
||||||
|
|
||||||
const spy = jasmine.createSpy('late attached')
|
const spy = vi.fn()
|
||||||
Test.options.beforeCreate = Test.options.beforeCreate.concat(spy)
|
Test.options.beforeCreate = Test.options.beforeCreate.concat(spy)
|
||||||
|
|
||||||
// Update super constructor's options
|
// Update super constructor's options
|
||||||
const mixinSpy = jasmine.createSpy('mixin')
|
const mixinSpy = vi.fn()
|
||||||
Vue.mixin({
|
Vue.mixin({
|
||||||
beforeCreate: mixinSpy
|
beforeCreate: mixinSpy
|
||||||
})
|
})
|
||||||
@ -114,9 +114,9 @@ describe('Global API: mixin', () => {
|
|||||||
template: '<div>{{ $style }}</div>'
|
template: '<div>{{ $style }}</div>'
|
||||||
}).$mount()
|
}).$mount()
|
||||||
|
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(baseSpy.calls.count()).toBe(1)
|
expect(baseSpy.mock.calls.length).toBe(1)
|
||||||
expect(mixinSpy.calls.count()).toBe(1)
|
expect(mixinSpy.mock.calls.length).toBe(1)
|
||||||
expect(vm.$el.textContent).toBe('123')
|
expect(vm.$el.textContent).toBe('123')
|
||||||
expect(vm.$style).toBe(123)
|
expect(vm.$style).toBe(123)
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ describe('Global API: mixin', () => {
|
|||||||
|
|
||||||
// vue-class-component#83
|
// vue-class-component#83
|
||||||
it('should work for a constructor mixin', () => {
|
it('should work for a constructor mixin', () => {
|
||||||
const spy = jasmine.createSpy('global mixin')
|
const spy = vi.fn()
|
||||||
const Mixin = Vue.extend({
|
const Mixin = Vue.extend({
|
||||||
created () {
|
created () {
|
||||||
spy(this.$options.myOption)
|
spy(this.$options.myOption)
|
||||||
@ -144,13 +144,13 @@ describe('Global API: mixin', () => {
|
|||||||
|
|
||||||
// vue-class-component#87
|
// vue-class-component#87
|
||||||
it('should not drop original lifecycle hooks', () => {
|
it('should not drop original lifecycle hooks', () => {
|
||||||
const base = jasmine.createSpy('base')
|
const base = vi.fn()
|
||||||
|
|
||||||
const Base = Vue.extend({
|
const Base = Vue.extend({
|
||||||
beforeCreate: base
|
beforeCreate: base
|
||||||
})
|
})
|
||||||
|
|
||||||
const injected = jasmine.createSpy('injected')
|
const injected = vi.fn()
|
||||||
|
|
||||||
// inject a function
|
// inject a function
|
||||||
Base.options.beforeCreate = Base.options.beforeCreate.concat(injected)
|
Base.options.beforeCreate = Base.options.beforeCreate.concat(injected)
|
||||||
@ -170,7 +170,7 @@ describe('Global API: mixin', () => {
|
|||||||
|
|
||||||
// #9198
|
// #9198
|
||||||
it('should not mix global mixin lifecycle hook twice', () => {
|
it('should not mix global mixin lifecycle hook twice', () => {
|
||||||
const spy = jasmine.createSpy('global mixed in lifecycle hook')
|
const spy = vi.fn()
|
||||||
Vue.mixin({
|
Vue.mixin({
|
||||||
created: spy
|
created: spy
|
||||||
})
|
})
|
||||||
@ -192,6 +192,6 @@ describe('Global API: mixin', () => {
|
|||||||
const vm = new Child()
|
const vm = new Child()
|
||||||
|
|
||||||
expect(typeof vm.$options.methods.a).toBe('function')
|
expect(typeof vm.$options.methods.a).toBe('function')
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -21,7 +21,7 @@ describe('Instance methods data', () => {
|
|||||||
describe('$watch', () => {
|
describe('$watch', () => {
|
||||||
let vm, spy
|
let vm, spy
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spy = jasmine.createSpy('watch')
|
spy = vi.fn()
|
||||||
vm = new Vue({
|
vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
a: {
|
a: {
|
||||||
@ -41,18 +41,18 @@ describe('Instance methods data', () => {
|
|||||||
vm.$watch('a.b', spy)
|
vm.$watch('a.b', spy)
|
||||||
vm.a.b = 2
|
vm.a.b = 2
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy).toHaveBeenCalledWith(2, 1)
|
expect(spy).toHaveBeenCalledWith(2, 1)
|
||||||
vm.a = { b: 3 }
|
vm.a = { b: 3 }
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
expect(spy).toHaveBeenCalledWith(3, 2)
|
expect(spy).toHaveBeenCalledWith(3, 2)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('immediate', () => {
|
it('immediate', () => {
|
||||||
vm.$watch('a.b', spy, { immediate: true })
|
vm.$watch('a.b', spy, { immediate: true })
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy).toHaveBeenCalledWith(1)
|
expect(spy).toHaveBeenCalledWith(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ describe('Instance methods data', () => {
|
|||||||
unwatch()
|
unwatch()
|
||||||
vm.a.b = 2
|
vm.a.b = 2
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ describe('Instance methods data', () => {
|
|||||||
handler: 'foo',
|
handler: 'foo',
|
||||||
immediate: true
|
immediate: true
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy).toHaveBeenCalledWith(1)
|
expect(spy).toHaveBeenCalledWith(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ describe('Instance methods data', () => {
|
|||||||
handler: 'foo',
|
handler: 'foo',
|
||||||
immediate: true
|
immediate: true
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy).toHaveBeenCalledWith('ok')
|
expect(spy).toHaveBeenCalledWith('ok')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ describe('Instance methods events', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const vm = new Vue()
|
const vm = new Vue()
|
||||||
spy = jasmine.createSpy('emitter')
|
spy = vi.fn()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('$on', () => {
|
it('$on', () => {
|
||||||
@ -15,7 +15,7 @@ describe('Instance methods events', () => {
|
|||||||
spy.apply(this, arguments)
|
spy.apply(this, arguments)
|
||||||
})
|
})
|
||||||
vm.$emit('test', 1, 2, 3, 4)
|
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)
|
expect(spy).toHaveBeenCalledWith(1, 2, 3, 4)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -25,10 +25,10 @@ describe('Instance methods events', () => {
|
|||||||
spy.apply(this, arguments)
|
spy.apply(this, arguments)
|
||||||
})
|
})
|
||||||
vm.$emit('test1', 1, 2, 3, 4)
|
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)
|
expect(spy).toHaveBeenCalledWith(1, 2, 3, 4)
|
||||||
vm.$emit('test2', 5, 6, 7, 8)
|
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)
|
expect(spy).toHaveBeenCalledWith(5, 6, 7, 8)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ describe('Instance methods events', () => {
|
|||||||
vm.$emit('test2')
|
vm.$emit('test2')
|
||||||
expect(spy).not.toHaveBeenCalled()
|
expect(spy).not.toHaveBeenCalled()
|
||||||
vm.$emit('test3', 1, 2, 3, 4)
|
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', () => {
|
it('$off multi event without callback', () => {
|
||||||
@ -53,7 +53,7 @@ describe('Instance methods events', () => {
|
|||||||
vm.$once('test', spy)
|
vm.$once('test', spy)
|
||||||
vm.$emit('test', 1, 2, 3)
|
vm.$emit('test', 1, 2, 3)
|
||||||
vm.$emit('test', 2, 3, 4)
|
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)
|
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.$off('test1') // test off something that's already off
|
||||||
vm.$emit('test1', 1)
|
vm.$emit('test1', 1)
|
||||||
vm.$emit('test2', 2)
|
vm.$emit('test2', 2)
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy).toHaveBeenCalledWith(2)
|
expect(spy).toHaveBeenCalledWith(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('$off event + fn', () => {
|
it('$off event + fn', () => {
|
||||||
const spy2 = jasmine.createSpy('emitter')
|
const spy2 = vi.fn()
|
||||||
vm.$on('test', spy)
|
vm.$on('test', spy)
|
||||||
vm.$on('test', spy2)
|
vm.$on('test', spy2)
|
||||||
vm.$off('test', spy)
|
vm.$off('test', spy)
|
||||||
vm.$emit('test', 1, 2, 3)
|
vm.$emit('test', 1, 2, 3)
|
||||||
expect(spy).not.toHaveBeenCalled()
|
expect(spy).not.toHaveBeenCalled()
|
||||||
expect(spy2.calls.count()).toBe(1)
|
expect(spy2.mock.calls.length).toBe(1)
|
||||||
expect(spy2).toHaveBeenCalledWith(1, 2, 3)
|
expect(spy2).toHaveBeenCalledWith(1, 2, 3)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -57,7 +57,7 @@ describe('Instance methods lifecycle', () => {
|
|||||||
it('Dep.target should be undefined during invocation of child immediate watcher', done => {
|
it('Dep.target should be undefined during invocation of child immediate watcher', done => {
|
||||||
let calls = 0
|
let calls = 0
|
||||||
const childData = { a: 1 }
|
const childData = { a: 1 }
|
||||||
const parentUpdate = jasmine.createSpy()
|
const parentUpdate = vi.fn()
|
||||||
new Vue({
|
new Vue({
|
||||||
template: '<div><my-component></my-component></div>',
|
template: '<div><my-component></my-component></div>',
|
||||||
updated: parentUpdate,
|
updated: parentUpdate,
|
||||||
@ -117,13 +117,13 @@ describe('Instance methods lifecycle', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('avoid duplicate calls', () => {
|
it('avoid duplicate calls', () => {
|
||||||
const spy = jasmine.createSpy('destroy')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
beforeDestroy: spy
|
beforeDestroy: spy
|
||||||
})
|
})
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -168,8 +168,8 @@ describe('Instance properties', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('$listeners', done => {
|
it('$listeners', done => {
|
||||||
const spyA = jasmine.createSpy('A')
|
const spyA = vi.fn()
|
||||||
const spyB = jasmine.createSpy('B')
|
const spyB = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<foo @click="foo"/>`,
|
template: `<foo @click="foo"/>`,
|
||||||
data: { foo: spyA },
|
data: { foo: spyA },
|
||||||
@ -184,14 +184,14 @@ describe('Instance properties', () => {
|
|||||||
document.body.appendChild(vm.$el)
|
document.body.appendChild(vm.$el)
|
||||||
|
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spyA.calls.count()).toBe(1)
|
expect(spyA.mock.calls.length).toBe(1)
|
||||||
expect(spyB.calls.count()).toBe(0)
|
expect(spyB.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
vm.foo = spyB
|
vm.foo = spyB
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
triggerEvent(vm.$el, 'click')
|
triggerEvent(vm.$el, 'click')
|
||||||
expect(spyA.calls.count()).toBe(1)
|
expect(spyA.mock.calls.length).toBe(1)
|
||||||
expect(spyB.calls.count()).toBe(1)
|
expect(spyB.mock.calls.length).toBe(1)
|
||||||
document.body.removeChild(vm.$el)
|
document.body.removeChild(vm.$el)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
@ -91,7 +91,7 @@ describe('Options computed', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('watching computed', done => {
|
it('watching computed', done => {
|
||||||
const spy = jasmine.createSpy('watch computed')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
a: 1
|
a: 1
|
||||||
@ -108,7 +108,7 @@ describe('Options computed', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('caching', () => {
|
it('caching', () => {
|
||||||
const spy = jasmine.createSpy('cached computed')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
a: 1
|
a: 1
|
||||||
@ -120,15 +120,15 @@ describe('Options computed', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
vm.b
|
vm.b
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
vm.b
|
vm.b
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('cache: false', () => {
|
it('cache: false', () => {
|
||||||
const spy = jasmine.createSpy('cached computed')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
a: 1
|
a: 1
|
||||||
@ -143,11 +143,11 @@ describe('Options computed', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
expect(spy.calls.count()).toBe(0)
|
expect(spy.mock.calls.length).toBe(0)
|
||||||
vm.b
|
vm.b
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
vm.b
|
vm.b
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('as component', done => {
|
it('as component', done => {
|
||||||
|
@ -2,11 +2,11 @@ import Vue from 'vue'
|
|||||||
|
|
||||||
describe('Options directives', () => {
|
describe('Options directives', () => {
|
||||||
it('basic usage', done => {
|
it('basic usage', done => {
|
||||||
const bindSpy = jasmine.createSpy('bind')
|
const bindSpy = vi.fn()
|
||||||
const insertedSpy = jasmine.createSpy('inserted')
|
const insertedSpy = vi.fn()
|
||||||
const updateSpy = jasmine.createSpy('update')
|
const updateSpy = vi.fn()
|
||||||
const componentUpdatedSpy = jasmine.createSpy('componentUpdated')
|
const componentUpdatedSpy = vi.fn()
|
||||||
const unbindSpy = jasmine.createSpy('unbind')
|
const unbindSpy = vi.fn()
|
||||||
|
|
||||||
const assertContext = (el, binding, vnode) => {
|
const assertContext = (el, binding, vnode) => {
|
||||||
expect(vnode.context).toBe(vm)
|
expect(vnode.context).toBe(vm)
|
||||||
@ -75,7 +75,7 @@ describe('Options directives', () => {
|
|||||||
expect(unbindSpy).not.toHaveBeenCalled()
|
expect(unbindSpy).not.toHaveBeenCalled()
|
||||||
vm.msg = 'bye'
|
vm.msg = 'bye'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(componentUpdatedSpy.calls.count()).toBe(2)
|
expect(componentUpdatedSpy.mock.calls.length).toBe(2)
|
||||||
vm.ok = false
|
vm.ok = false
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(unbindSpy).toHaveBeenCalled()
|
expect(unbindSpy).toHaveBeenCalled()
|
||||||
@ -83,7 +83,7 @@ describe('Options directives', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('function shorthand', done => {
|
it('function shorthand', done => {
|
||||||
const spy = jasmine.createSpy('directive')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: '<div v-test:arg.hello="a"></div>',
|
template: '<div v-test:arg.hello="a"></div>',
|
||||||
data: { a: 'foo' },
|
data: { a: 'foo' },
|
||||||
@ -105,7 +105,7 @@ describe('Options directives', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('function shorthand (global)', done => {
|
it('function shorthand (global)', done => {
|
||||||
const spy = jasmine.createSpy('directive')
|
const spy = vi.fn()
|
||||||
Vue.directive('test', function (el, binding, vnode) {
|
Vue.directive('test', function (el, binding, vnode) {
|
||||||
expect(vnode.context).toBe(vm)
|
expect(vnode.context).toBe(vm)
|
||||||
expect(binding.arg).toBe('arg')
|
expect(binding.arg).toBe('arg')
|
||||||
@ -153,7 +153,7 @@ describe('Options directives', () => {
|
|||||||
|
|
||||||
it('should properly handle same node with different directive sets', done => {
|
it('should properly handle same node with different directive sets', done => {
|
||||||
const spies = {}
|
const spies = {}
|
||||||
const createSpy = name => (spies[name] = jasmine.createSpy(name))
|
const createSpy = name => (spies[name] = vi.fn())
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
ok: true,
|
ok: true,
|
||||||
@ -183,41 +183,41 @@ describe('Options directives', () => {
|
|||||||
}
|
}
|
||||||
}).$mount()
|
}).$mount()
|
||||||
|
|
||||||
expect(spies.bind1.calls.count()).toBe(2)
|
expect(spies.bind1.mock.calls.length).toBe(2)
|
||||||
expect(spies.inserted1.calls.count()).toBe(2)
|
expect(spies.inserted1.mock.calls.length).toBe(2)
|
||||||
expect(spies.bind2.calls.count()).toBe(0)
|
expect(spies.bind2.mock.calls.length).toBe(0)
|
||||||
expect(spies.inserted2.calls.count()).toBe(0)
|
expect(spies.inserted2.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
vm.ok = false
|
vm.ok = false
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
// v-test with modifier should be updated
|
// v-test with modifier should be updated
|
||||||
expect(spies.update1.calls.count()).toBe(1)
|
expect(spies.update1.mock.calls.length).toBe(1)
|
||||||
expect(spies.componentUpdated1.calls.count()).toBe(1)
|
expect(spies.componentUpdated1.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
// v-test without modifier should be unbound
|
// 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
|
// v-test2 should be bound
|
||||||
expect(spies.bind2.calls.count()).toBe(1)
|
expect(spies.bind2.mock.calls.length).toBe(1)
|
||||||
expect(spies.inserted2.calls.count()).toBe(1)
|
expect(spies.inserted2.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
vm.ok = true
|
vm.ok = true
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// v-test without modifier should be bound again
|
// v-test without modifier should be bound again
|
||||||
expect(spies.bind1.calls.count()).toBe(3)
|
expect(spies.bind1.mock.calls.length).toBe(3)
|
||||||
expect(spies.inserted1.calls.count()).toBe(3)
|
expect(spies.inserted1.mock.calls.length).toBe(3)
|
||||||
|
|
||||||
// v-test2 should be unbound
|
// 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
|
// v-test with modifier should be updated again
|
||||||
expect(spies.update1.calls.count()).toBe(2)
|
expect(spies.update1.mock.calls.length).toBe(2)
|
||||||
expect(spies.componentUpdated1.calls.count()).toBe(2)
|
expect(spies.componentUpdated1.mock.calls.length).toBe(2)
|
||||||
|
|
||||||
vm.val = 234
|
vm.val = 234
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spies.update1.calls.count()).toBe(4)
|
expect(spies.update1.mock.calls.length).toBe(4)
|
||||||
expect(spies.componentUpdated1.calls.count()).toBe(4)
|
expect(spies.componentUpdated1.mock.calls.length).toBe(4)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -231,9 +231,9 @@ describe('Options directives', () => {
|
|||||||
// #6513
|
// #6513
|
||||||
it('should invoke unbind & inserted on inner component root element change', done => {
|
it('should invoke unbind & inserted on inner component root element change', done => {
|
||||||
const dir = {
|
const dir = {
|
||||||
bind: jasmine.createSpy('bind'),
|
bind: vi.fn(),
|
||||||
inserted: jasmine.createSpy('inserted'),
|
inserted: vi.fn(),
|
||||||
unbind: jasmine.createSpy('unbind')
|
unbind: vi.fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
const Child = {
|
const Child = {
|
||||||
@ -248,20 +248,20 @@ describe('Options directives', () => {
|
|||||||
}).$mount()
|
}).$mount()
|
||||||
|
|
||||||
const oldEl = vm.$el
|
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.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.inserted.calls.argsFor(0)[0]).toBe(oldEl)
|
||||||
expect(dir.unbind).not.toHaveBeenCalled()
|
expect(dir.unbind).not.toHaveBeenCalled()
|
||||||
|
|
||||||
vm.$refs.child.ok = false
|
vm.$refs.child.ok = false
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(vm.$el.tagName).toBe('SPAN')
|
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.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.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)
|
expect(dir.unbind.calls.argsFor(0)[0]).toBe(oldEl)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
@ -4,7 +4,7 @@ describe('Options errorCaptured', () => {
|
|||||||
let globalSpy
|
let globalSpy
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
globalSpy = Vue.config.errorHandler = jasmine.createSpy()
|
globalSpy = Vue.config.errorHandler = vi.fn()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -12,7 +12,7 @@ describe('Options errorCaptured', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should capture error from child component', () => {
|
it('should capture error from child component', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
|
|
||||||
let child
|
let child
|
||||||
let err
|
let err
|
||||||
@ -68,7 +68,7 @@ describe('Options errorCaptured', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should not propagate to global handler when returning true', () => {
|
it('should not propagate to global handler when returning true', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
|
|
||||||
let child
|
let child
|
||||||
let err
|
let err
|
||||||
@ -249,7 +249,7 @@ describe('Options errorCaptured', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should capture error from watcher', done => {
|
it('should capture error from watcher', done => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
|
|
||||||
let child
|
let child
|
||||||
let err
|
let err
|
||||||
@ -285,7 +285,7 @@ describe('Options errorCaptured', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should capture promise error from watcher', done => {
|
it('should capture promise error from watcher', done => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
|
|
||||||
let child
|
let child
|
||||||
let err
|
let err
|
||||||
@ -323,7 +323,7 @@ describe('Options errorCaptured', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should capture error from immediate watcher', done => {
|
it('should capture error from immediate watcher', done => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
|
|
||||||
let child
|
let child
|
||||||
let err
|
let err
|
||||||
@ -360,7 +360,7 @@ describe('Options errorCaptured', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should capture promise error from immediate watcher', done => {
|
it('should capture promise error from immediate watcher', done => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
|
|
||||||
let child
|
let child
|
||||||
let err
|
let err
|
||||||
|
@ -52,7 +52,7 @@ describe('Options extends', () => {
|
|||||||
it('should work with global mixins + Object.prototype.watch', done => {
|
it('should work with global mixins + Object.prototype.watch', done => {
|
||||||
Vue.mixin({})
|
Vue.mixin({})
|
||||||
|
|
||||||
const spy = jasmine.createSpy('watch')
|
const spy = vi.fn()
|
||||||
const A = Vue.extend({
|
const A = Vue.extend({
|
||||||
data: function () {
|
data: function () {
|
||||||
return { a: 1 }
|
return { a: 1 }
|
||||||
|
@ -51,8 +51,8 @@ describe('Options functional', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should expose data.on as listeners', () => {
|
it('should expose data.on as listeners', () => {
|
||||||
const foo = jasmine.createSpy('foo')
|
const foo = vi.fn()
|
||||||
const bar = jasmine.createSpy('bar')
|
const bar = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: '<div><wrap @click="foo" @test="bar"/></div>',
|
template: '<div><wrap @click="foo" @test="bar"/></div>',
|
||||||
methods: { foo, bar },
|
methods: { foo, bar },
|
||||||
@ -134,7 +134,7 @@ describe('Options functional', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should let vnode raw data pass through', done => {
|
it('should let vnode raw data pass through', done => {
|
||||||
const onValid = jasmine.createSpy('valid')
|
const onValid = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: { msg: 'hello' },
|
data: { msg: 'hello' },
|
||||||
template: `<div>
|
template: `<div>
|
||||||
|
@ -3,7 +3,7 @@ import Vue from 'vue'
|
|||||||
describe('Options lifecycle hooks', () => {
|
describe('Options lifecycle hooks', () => {
|
||||||
let spy
|
let spy
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spy = jasmine.createSpy('hook')
|
spy = vi.fn()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('beforeCreate', () => {
|
describe('beforeCreate', () => {
|
||||||
@ -156,8 +156,8 @@ describe('Options lifecycle hooks', () => {
|
|||||||
|
|
||||||
// #8076
|
// #8076
|
||||||
it('should not be called after destroy', done => {
|
it('should not be called after destroy', done => {
|
||||||
const beforeUpdate = jasmine.createSpy('beforeUpdate')
|
const beforeUpdate = vi.fn()
|
||||||
const destroyed = jasmine.createSpy('destroyed')
|
const destroyed = vi.fn()
|
||||||
|
|
||||||
Vue.component('todo', {
|
Vue.component('todo', {
|
||||||
template: '<div>{{todo.done}}</div>',
|
template: '<div>{{todo.done}}</div>',
|
||||||
@ -240,8 +240,8 @@ describe('Options lifecycle hooks', () => {
|
|||||||
|
|
||||||
// #8076
|
// #8076
|
||||||
it('should not be called after destroy', done => {
|
it('should not be called after destroy', done => {
|
||||||
const updated = jasmine.createSpy('updated')
|
const updated = vi.fn()
|
||||||
const destroyed = jasmine.createSpy('destroyed')
|
const destroyed = vi.fn()
|
||||||
|
|
||||||
Vue.component('todo', {
|
Vue.component('todo', {
|
||||||
template: '<div>{{todo.done}}</div>',
|
template: '<div>{{todo.done}}</div>',
|
||||||
@ -290,7 +290,7 @@ describe('Options lifecycle hooks', () => {
|
|||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
expect(spy).toHaveBeenCalled()
|
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()
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
expect(spy).toHaveBeenCalled()
|
expect(spy).toHaveBeenCalled()
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should emit hook events', () => {
|
it('should emit hook events', () => {
|
||||||
const created = jasmine.createSpy()
|
const created = vi.fn()
|
||||||
const mounted = jasmine.createSpy()
|
const mounted = vi.fn()
|
||||||
const destroyed = jasmine.createSpy()
|
const destroyed = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
render () {},
|
render () {},
|
||||||
beforeCreate () {
|
beforeCreate () {
|
||||||
|
@ -111,8 +111,8 @@ describe('Options mixins', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should accept further extended constructors as mixins', () => {
|
it('should accept further extended constructors as mixins', () => {
|
||||||
const spy1 = jasmine.createSpy('mixinA')
|
const spy1 = vi.fn()
|
||||||
const spy2 = jasmine.createSpy('mixinB')
|
const spy2 = vi.fn()
|
||||||
|
|
||||||
const mixinA = Vue.extend({
|
const mixinA = Vue.extend({
|
||||||
created: spy1,
|
created: spy1,
|
||||||
|
@ -169,56 +169,56 @@ describe('Options props', () => {
|
|||||||
|
|
||||||
it('string', () => {
|
it('string', () => {
|
||||||
makeInstance('hello', String)
|
makeInstance('hello', String)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance(123, String)
|
makeInstance(123, String)
|
||||||
expect('Expected String with value "123", got Number with value 123').toHaveBeenWarned()
|
expect('Expected String with value "123", got Number with value 123').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('number', () => {
|
it('number', () => {
|
||||||
makeInstance(123, Number)
|
makeInstance(123, Number)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance('123', Number)
|
makeInstance('123', Number)
|
||||||
expect('Expected Number with value 123, got String with value "123"').toHaveBeenWarned()
|
expect('Expected Number with value 123, got String with value "123"').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('number & boolean', () => {
|
it('number & boolean', () => {
|
||||||
makeInstance(123, Number)
|
makeInstance(123, Number)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance(false, Number)
|
makeInstance(false, Number)
|
||||||
expect('Expected Number, got Boolean with value false').toHaveBeenWarned()
|
expect('Expected Number, got Boolean with value false').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('string & boolean', () => {
|
it('string & boolean', () => {
|
||||||
makeInstance('hello', String)
|
makeInstance('hello', String)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance(true, String)
|
makeInstance(true, String)
|
||||||
expect('Expected String, got Boolean with value true').toHaveBeenWarned()
|
expect('Expected String, got Boolean with value true').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('boolean', () => {
|
it('boolean', () => {
|
||||||
makeInstance(true, Boolean)
|
makeInstance(true, Boolean)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance('123', Boolean)
|
makeInstance('123', Boolean)
|
||||||
expect('Expected Boolean, got String with value "123"').toHaveBeenWarned()
|
expect('Expected Boolean, got String with value "123"').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('function', () => {
|
it('function', () => {
|
||||||
makeInstance(() => {}, Function)
|
makeInstance(() => {}, Function)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance(123, Function)
|
makeInstance(123, Function)
|
||||||
expect('Expected Function, got Number with value 123').toHaveBeenWarned()
|
expect('Expected Function, got Number with value 123').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('object', () => {
|
it('object', () => {
|
||||||
makeInstance({}, Object)
|
makeInstance({}, Object)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance([], Object)
|
makeInstance([], Object)
|
||||||
expect('Expected Object, got Array').toHaveBeenWarned()
|
expect('Expected Object, got Array').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('array', () => {
|
it('array', () => {
|
||||||
makeInstance([], Array)
|
makeInstance([], Array)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance({}, Array)
|
makeInstance({}, Array)
|
||||||
expect('Expected Array, got Object').toHaveBeenWarned()
|
expect('Expected Array, got Object').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
@ -226,18 +226,18 @@ describe('Options props', () => {
|
|||||||
it('primitive wrapper objects', () => {
|
it('primitive wrapper objects', () => {
|
||||||
/* eslint-disable no-new-wrappers */
|
/* eslint-disable no-new-wrappers */
|
||||||
makeInstance(new String('s'), String)
|
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)
|
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)
|
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 */
|
/* eslint-enable no-new-wrappers */
|
||||||
})
|
})
|
||||||
|
|
||||||
if (hasSymbol) {
|
if (hasSymbol) {
|
||||||
it('symbol', () => {
|
it('symbol', () => {
|
||||||
makeInstance(Symbol('foo'), Symbol)
|
makeInstance(Symbol('foo'), Symbol)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance({}, Symbol)
|
makeInstance({}, Symbol)
|
||||||
expect('Expected Symbol, got Object').toHaveBeenWarned()
|
expect('Expected Symbol, got Object').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
@ -252,12 +252,12 @@ describe('Options props', () => {
|
|||||||
expect('Expected String, Number, got Symbol').toHaveBeenWarned()
|
expect('Expected String, Number, got Symbol').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof BigInt !== 'undefined') {
|
if (typeof BigInt !== 'undefined') {
|
||||||
/* global BigInt */
|
/* global BigInt */
|
||||||
it('bigint', () => {
|
it('bigint', () => {
|
||||||
makeInstance(BigInt(100), BigInt)
|
makeInstance(BigInt(100), BigInt)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance({}, BigInt)
|
makeInstance({}, BigInt)
|
||||||
expect('Expected BigInt, got Object').toHaveBeenWarned()
|
expect('Expected BigInt, got Object').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
@ -266,28 +266,28 @@ describe('Options props', () => {
|
|||||||
it('custom constructor', () => {
|
it('custom constructor', () => {
|
||||||
function Class () {}
|
function Class () {}
|
||||||
makeInstance(new Class(), Class)
|
makeInstance(new Class(), Class)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance({}, Class)
|
makeInstance({}, Class)
|
||||||
expect('type check failed').toHaveBeenWarned()
|
expect('type check failed').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('multiple types', () => {
|
it('multiple types', () => {
|
||||||
makeInstance([], [Array, Number, Boolean])
|
makeInstance([], [Array, Number, Boolean])
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance({}, [Array, Number, Boolean])
|
makeInstance({}, [Array, Number, Boolean])
|
||||||
expect('Expected Array, Number, Boolean, got Object').toHaveBeenWarned()
|
expect('Expected Array, Number, Boolean, got Object').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('custom validator', () => {
|
it('custom validator', () => {
|
||||||
makeInstance(123, null, v => v === 123)
|
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)
|
makeInstance(123, null, v => v === 234)
|
||||||
expect('custom validator check failed').toHaveBeenWarned()
|
expect('custom validator check failed').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('type check + custom validator', () => {
|
it('type check + custom validator', () => {
|
||||||
makeInstance(123, Number, v => v === 123)
|
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)
|
makeInstance(123, Number, v => v === 234)
|
||||||
expect('custom validator check failed').toHaveBeenWarned()
|
expect('custom validator check failed').toHaveBeenWarned()
|
||||||
makeInstance(123, String, v => v === 123)
|
makeInstance(123, String, v => v === 123)
|
||||||
@ -296,7 +296,7 @@ describe('Options props', () => {
|
|||||||
|
|
||||||
it('multiple types + custom validator', () => {
|
it('multiple types + custom validator', () => {
|
||||||
makeInstance(123, [Number, String, Boolean], v => v === 123)
|
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)
|
makeInstance(123, [Number, String, Boolean], v => v === 234)
|
||||||
expect('custom validator check failed').toHaveBeenWarned()
|
expect('custom validator check failed').toHaveBeenWarned()
|
||||||
makeInstance(123, [String, Boolean], v => v === 123)
|
makeInstance(123, [String, Boolean], v => v === 123)
|
||||||
@ -305,31 +305,31 @@ describe('Options props', () => {
|
|||||||
|
|
||||||
it('optional with type + null/undefined', () => {
|
it('optional with type + null/undefined', () => {
|
||||||
makeInstance(undefined, String)
|
makeInstance(undefined, String)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance(null, String)
|
makeInstance(null, String)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('required with type + null/undefined', () => {
|
it('required with type + null/undefined', () => {
|
||||||
makeInstance(undefined, String, null, true)
|
makeInstance(undefined, String, null, true)
|
||||||
expect(console.error.calls.count()).toBe(1)
|
expect(console.error.mock.calls.length).toBe(1)
|
||||||
expect('Expected String').toHaveBeenWarned()
|
expect('Expected String').toHaveBeenWarned()
|
||||||
makeInstance(null, Boolean, null, true)
|
makeInstance(null, Boolean, null, true)
|
||||||
expect(console.error.calls.count()).toBe(2)
|
expect(console.error.mock.calls.length).toBe(2)
|
||||||
expect('Expected Boolean').toHaveBeenWarned()
|
expect('Expected Boolean').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('optional prop of any type (type: true or prop: true)', () => {
|
it('optional prop of any type (type: true or prop: true)', () => {
|
||||||
makeInstance(1, true)
|
makeInstance(1, true)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance('any', true)
|
makeInstance('any', true)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance({}, true)
|
makeInstance({}, true)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance(undefined, true)
|
makeInstance(undefined, true)
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
makeInstance(null, true)
|
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()
|
}).$mount()
|
||||||
expect(console.error.calls.count()).toBe(0)
|
expect(console.error.mock.calls.length).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
// #3453
|
// #3453
|
||||||
it('should not fire watcher on object/array props when parent re-renders', done => {
|
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({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
arr: []
|
arr: []
|
||||||
@ -497,7 +497,7 @@ describe('Options props', () => {
|
|||||||
|
|
||||||
// #4090
|
// #4090
|
||||||
it('should not trigger watcher on default value', done => {
|
it('should not trigger watcher on default value', done => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<test :value="a" :test="b"></test>`,
|
template: `<test :value="a" :test="b"></test>`,
|
||||||
data: {
|
data: {
|
||||||
@ -526,14 +526,14 @@ describe('Options props', () => {
|
|||||||
expect(spy).not.toHaveBeenCalled()
|
expect(spy).not.toHaveBeenCalled()
|
||||||
vm.b = {}
|
vm.b = {}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
vm.b = undefined
|
vm.b = undefined
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
vm.a++
|
vm.a++
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ describe('Options renderError', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should pass on errors in renderError to global handler', () => {
|
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 err = new Error('renderError')
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
render () {
|
render () {
|
||||||
|
@ -5,7 +5,7 @@ import { finished } from 'stream';
|
|||||||
describe('Options watch', () => {
|
describe('Options watch', () => {
|
||||||
let spy
|
let spy
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spy = jasmine.createSpy('watch')
|
spy = vi.fn()
|
||||||
})
|
})
|
||||||
|
|
||||||
testObjectOption('watch')
|
testObjectOption('watch')
|
||||||
@ -48,7 +48,7 @@ describe('Options watch', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('multiple cbs (after option merge)', done => {
|
it('multiple cbs (after option merge)', done => {
|
||||||
const spy1 = jasmine.createSpy('watch')
|
const spy1 = vi.fn()
|
||||||
const Test = Vue.extend({
|
const Test = Vue.extend({
|
||||||
watch: {
|
watch: {
|
||||||
a: spy1
|
a: spy1
|
||||||
@ -107,8 +107,8 @@ describe('Options watch', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('correctly merges multiple extends', done => {
|
it('correctly merges multiple extends', done => {
|
||||||
const spy2 = jasmine.createSpy('A')
|
const spy2 = vi.fn()
|
||||||
const spy3 = jasmine.createSpy('B')
|
const spy3 = vi.fn()
|
||||||
const A = Vue.extend({
|
const A = Vue.extend({
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
|
@ -177,9 +177,9 @@ if (!isIE9) {
|
|||||||
|
|
||||||
it('events', done => {
|
it('events', done => {
|
||||||
let next
|
let next
|
||||||
const beforeEnterSpy = jasmine.createSpy()
|
const beforeEnterSpy = vi.fn()
|
||||||
const afterEnterSpy = jasmine.createSpy()
|
const afterEnterSpy = vi.fn()
|
||||||
const afterLeaveSpy = jasmine.createSpy()
|
const afterLeaveSpy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `
|
template: `
|
||||||
<div>
|
<div>
|
||||||
@ -219,7 +219,7 @@ if (!isIE9) {
|
|||||||
`<div class="test v-enter v-enter-active">d</div>` +
|
`<div class="test v-enter v-enter-active">d</div>` +
|
||||||
`</span>`
|
`</span>`
|
||||||
)
|
)
|
||||||
expect(beforeEnterSpy.calls.count()).toBe(1)
|
expect(beforeEnterSpy.mock.calls.length).toBe(1)
|
||||||
}).thenWaitFor(_next => { next = _next }).then(() => {
|
}).thenWaitFor(_next => { next = _next }).then(() => {
|
||||||
expect(vm.$el.innerHTML).toBe(
|
expect(vm.$el.innerHTML).toBe(
|
||||||
`<span>` +
|
`<span>` +
|
||||||
@ -229,7 +229,7 @@ if (!isIE9) {
|
|||||||
`<div class="test">d</div>` +
|
`<div class="test">d</div>` +
|
||||||
`</span>`
|
`</span>`
|
||||||
)
|
)
|
||||||
expect(afterEnterSpy.calls.count()).toBe(1)
|
expect(afterEnterSpy.mock.calls.length).toBe(1)
|
||||||
vm.items.shift()
|
vm.items.shift()
|
||||||
}).thenWaitFor(_next => { next = _next }).then(() => {
|
}).thenWaitFor(_next => { next = _next }).then(() => {
|
||||||
expect(vm.$el.innerHTML).toBe(
|
expect(vm.$el.innerHTML).toBe(
|
||||||
@ -239,7 +239,7 @@ if (!isIE9) {
|
|||||||
`<div class="test">d</div>` +
|
`<div class="test">d</div>` +
|
||||||
`</span>`
|
`</span>`
|
||||||
)
|
)
|
||||||
expect(afterLeaveSpy.calls.count()).toBe(1)
|
expect(afterLeaveSpy.mock.calls.length).toBe(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -137,8 +137,8 @@ if (!isIE9) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('inline transition object', done => {
|
it('inline transition object', done => {
|
||||||
const enter = jasmine.createSpy('enter')
|
const enter = vi.fn()
|
||||||
const leave = jasmine.createSpy('leave')
|
const leave = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
render (h) {
|
render (h) {
|
||||||
return h('div', null, [
|
return h('div', null, [
|
||||||
@ -184,12 +184,12 @@ if (!isIE9) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('transition events', done => {
|
it('transition events', done => {
|
||||||
const onLeaveSpy = jasmine.createSpy('leave')
|
const onLeaveSpy = vi.fn()
|
||||||
const onEnterSpy = jasmine.createSpy('enter')
|
const onEnterSpy = vi.fn()
|
||||||
const beforeLeaveSpy = jasmine.createSpy('beforeLeave')
|
const beforeLeaveSpy = vi.fn()
|
||||||
const beforeEnterSpy = jasmine.createSpy('beforeEnter')
|
const beforeEnterSpy = vi.fn()
|
||||||
const afterLeaveSpy = jasmine.createSpy('afterLeave')
|
const afterLeaveSpy = vi.fn()
|
||||||
const afterEnterSpy = jasmine.createSpy('afterEnter')
|
const afterEnterSpy = vi.fn()
|
||||||
|
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `
|
template: `
|
||||||
@ -259,12 +259,12 @@ if (!isIE9) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('transition events (v-show)', done => {
|
it('transition events (v-show)', done => {
|
||||||
const onLeaveSpy = jasmine.createSpy('leave')
|
const onLeaveSpy = vi.fn()
|
||||||
const onEnterSpy = jasmine.createSpy('enter')
|
const onEnterSpy = vi.fn()
|
||||||
const beforeLeaveSpy = jasmine.createSpy('beforeLeave')
|
const beforeLeaveSpy = vi.fn()
|
||||||
const beforeEnterSpy = jasmine.createSpy('beforeEnter')
|
const beforeEnterSpy = vi.fn()
|
||||||
const afterLeaveSpy = jasmine.createSpy('afterLeave')
|
const afterLeaveSpy = vi.fn()
|
||||||
const afterEnterSpy = jasmine.createSpy('afterEnter')
|
const afterEnterSpy = vi.fn()
|
||||||
|
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `
|
template: `
|
||||||
@ -386,8 +386,8 @@ if (!isIE9) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('css: false', done => {
|
it('css: false', done => {
|
||||||
const enterSpy = jasmine.createSpy('enter')
|
const enterSpy = vi.fn()
|
||||||
const leaveSpy = jasmine.createSpy('leave')
|
const leaveSpy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `
|
template: `
|
||||||
<div>
|
<div>
|
||||||
@ -415,8 +415,8 @@ if (!isIE9) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('no transition detected', done => {
|
it('no transition detected', done => {
|
||||||
const enterSpy = jasmine.createSpy('enter')
|
const enterSpy = vi.fn()
|
||||||
const leaveSpy = jasmine.createSpy('leave')
|
const leaveSpy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: '<div><transition name="nope" @enter="enter" @leave="leave"><div v-if="ok">foo</div></transition></div>',
|
template: '<div><transition name="nope" @enter="enter" @leave="leave"><div v-if="ok">foo</div></transition></div>',
|
||||||
data: { ok: true },
|
data: { ok: true },
|
||||||
@ -442,7 +442,7 @@ if (!isIE9) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('enterCancelled', done => {
|
it('enterCancelled', done => {
|
||||||
const spy = jasmine.createSpy('enterCancelled')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `
|
template: `
|
||||||
<div>
|
<div>
|
||||||
@ -476,7 +476,7 @@ if (!isIE9) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should remove stale leaving elements', done => {
|
it('should remove stale leaving elements', done => {
|
||||||
const spy = jasmine.createSpy('afterLeave')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `
|
template: `
|
||||||
<div>
|
<div>
|
||||||
@ -579,7 +579,7 @@ if (!isIE9) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('leaveCancelled (v-show only)', done => {
|
it('leaveCancelled (v-show only)', done => {
|
||||||
const spy = jasmine.createSpy('leaveCancelled')
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `
|
template: `
|
||||||
<div>
|
<div>
|
||||||
|
@ -622,7 +622,7 @@ describe('codegen', () => {
|
|||||||
`with(this){return _c("myComponent",{tag:"div"})}`
|
`with(this){return _c("myComponent",{tag:"div"})}`
|
||||||
)
|
)
|
||||||
expect('Inline-template components must have exactly one child element.').toHaveBeenWarned()
|
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', () => {
|
it('generate static trees inside v-for', () => {
|
||||||
|
@ -676,8 +676,8 @@ describe('parser', () => {
|
|||||||
|
|
||||||
it('pre/post transforms', () => {
|
it('pre/post transforms', () => {
|
||||||
const options = extend({}, baseOptions)
|
const options = extend({}, baseOptions)
|
||||||
const spy1 = jasmine.createSpy('preTransform')
|
const spy1 = vi.fn()
|
||||||
const spy2 = jasmine.createSpy('postTransform')
|
const spy2 = vi.fn()
|
||||||
options.modules = options.modules.concat([{
|
options.modules = options.modules.concat([{
|
||||||
preTransformNode (el) {
|
preTransformNode (el) {
|
||||||
spy1(el.tag)
|
spy1(el.tag)
|
||||||
|
@ -187,7 +187,7 @@ describe('Observer', () => {
|
|||||||
this.deps.push(dep)
|
this.deps.push(dep)
|
||||||
dep.addSub(this)
|
dep.addSub(this)
|
||||||
},
|
},
|
||||||
update: jasmine.createSpy()
|
update: vi.fn()
|
||||||
}
|
}
|
||||||
// collect dep
|
// collect dep
|
||||||
Dep.target = watcher
|
Dep.target = watcher
|
||||||
@ -195,10 +195,10 @@ describe('Observer', () => {
|
|||||||
Dep.target = null
|
Dep.target = null
|
||||||
expect(watcher.deps.length).toBe(3) // obj.a + a + a.b
|
expect(watcher.deps.length).toBe(3) // obj.a + a + a.b
|
||||||
obj.a.b = 3
|
obj.a.b = 3
|
||||||
expect(watcher.update.calls.count()).toBe(1)
|
expect(watcher.update.mock.calls.length).toBe(1)
|
||||||
// swap object
|
// swap object
|
||||||
obj.a = { b: 4 }
|
obj.a = { b: 4 }
|
||||||
expect(watcher.update.calls.count()).toBe(2)
|
expect(watcher.update.mock.calls.length).toBe(2)
|
||||||
watcher.deps = []
|
watcher.deps = []
|
||||||
|
|
||||||
Dep.target = watcher
|
Dep.target = watcher
|
||||||
@ -208,10 +208,10 @@ describe('Observer', () => {
|
|||||||
expect(watcher.deps.length).toBe(4)
|
expect(watcher.deps.length).toBe(4)
|
||||||
// set on the swapped object
|
// set on the swapped object
|
||||||
obj.a.b = 5
|
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
|
// should not trigger on NaN -> NaN set
|
||||||
obj.c = NaN
|
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', () => {
|
it('observing object prop change on defined property', () => {
|
||||||
@ -242,22 +242,22 @@ describe('Observer', () => {
|
|||||||
spyOn(dep1, 'notify')
|
spyOn(dep1, 'notify')
|
||||||
setProp(obj1, 'b', 2)
|
setProp(obj1, 'b', 2)
|
||||||
expect(obj1.b).toBe(2)
|
expect(obj1.b).toBe(2)
|
||||||
expect(dep1.notify.calls.count()).toBe(1)
|
expect(dep1.notify.mock.calls.length).toBe(1)
|
||||||
delProp(obj1, 'a')
|
delProp(obj1, 'a')
|
||||||
expect(hasOwn(obj1, 'a')).toBe(false)
|
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
|
// set existing key, should be a plain set and not
|
||||||
// trigger own ob's notify
|
// trigger own ob's notify
|
||||||
setProp(obj1, 'b', 3)
|
setProp(obj1, 'b', 3)
|
||||||
expect(obj1.b).toBe(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
|
// set non-existing key
|
||||||
setProp(obj1, 'c', 1)
|
setProp(obj1, 'c', 1)
|
||||||
expect(obj1.c).toBe(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
|
// should ignore deleting non-existing key
|
||||||
delProp(obj1, 'a')
|
delProp(obj1, 'a')
|
||||||
expect(dep1.notify.calls.count()).toBe(3)
|
expect(dep1.notify.mock.calls.length).toBe(3)
|
||||||
// should work on non-observed objects
|
// should work on non-observed objects
|
||||||
const obj2 = { a: 1 }
|
const obj2 = { a: 1 }
|
||||||
delProp(obj2, 'a')
|
delProp(obj2, 'a')
|
||||||
@ -270,10 +270,10 @@ describe('Observer', () => {
|
|||||||
spyOn(dep3, 'notify')
|
spyOn(dep3, 'notify')
|
||||||
setProp(obj3, 'b', 2)
|
setProp(obj3, 'b', 2)
|
||||||
expect(obj3.b).toBe(2)
|
expect(obj3.b).toBe(2)
|
||||||
expect(dep3.notify.calls.count()).toBe(1)
|
expect(dep3.notify.mock.calls.length).toBe(1)
|
||||||
delProp(obj3, 'a')
|
delProp(obj3, 'a')
|
||||||
expect(hasOwn(obj3, 'a')).toBe(false)
|
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
|
// set and delete non-numeric key on array
|
||||||
const arr2 = ['a']
|
const arr2 = ['a']
|
||||||
const ob2 = observe(arr2)
|
const ob2 = observe(arr2)
|
||||||
@ -281,10 +281,10 @@ describe('Observer', () => {
|
|||||||
spyOn(dep2, 'notify')
|
spyOn(dep2, 'notify')
|
||||||
setProp(arr2, 'b', 2)
|
setProp(arr2, 'b', 2)
|
||||||
expect(arr2.b).toBe(2)
|
expect(arr2.b).toBe(2)
|
||||||
expect(dep2.notify.calls.count()).toBe(1)
|
expect(dep2.notify.mock.calls.length).toBe(1)
|
||||||
delProp(arr2, 'b')
|
delProp(arr2, 'b')
|
||||||
expect(hasOwn(arr2, 'b')).toBe(false)
|
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 => {
|
it('warning set/delete on a Vue instance', done => {
|
||||||
@ -339,7 +339,7 @@ describe('Observer', () => {
|
|||||||
arr.splice(0, 0, objs[2])
|
arr.splice(0, 0, objs[2])
|
||||||
arr.sort()
|
arr.sort()
|
||||||
arr.reverse()
|
arr.reverse()
|
||||||
expect(dep.notify.calls.count()).toBe(7)
|
expect(dep.notify.mock.calls.length).toBe(7)
|
||||||
// inserted elements should be observed
|
// inserted elements should be observed
|
||||||
objs.forEach(obj => {
|
objs.forEach(obj => {
|
||||||
expect(obj.__ob__ instanceof Observer).toBe(true)
|
expect(obj.__ob__ instanceof Observer).toBe(true)
|
||||||
|
@ -12,7 +12,7 @@ function queueWatcher (watcher) {
|
|||||||
describe('Scheduler', () => {
|
describe('Scheduler', () => {
|
||||||
let spy
|
let spy
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spy = jasmine.createSpy('scheduler')
|
spy = vi.fn()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('queueWatcher', done => {
|
it('queueWatcher', done => {
|
||||||
@ -20,7 +20,7 @@ describe('Scheduler', () => {
|
|||||||
run: spy
|
run: spy
|
||||||
})
|
})
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ describe('Scheduler', () => {
|
|||||||
run: spy
|
run: spy
|
||||||
})
|
})
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ describe('Scheduler', () => {
|
|||||||
run () { queueWatcher(job) }
|
run () { queueWatcher(job) }
|
||||||
})
|
})
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ describe('Watcher', () => {
|
|||||||
msg: 'yo'
|
msg: 'yo'
|
||||||
}
|
}
|
||||||
}).$mount()
|
}).$mount()
|
||||||
spy = jasmine.createSpy('watcher')
|
spy = vi.fn()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('path', done => {
|
it('path', done => {
|
||||||
@ -44,7 +44,7 @@ describe('Watcher', () => {
|
|||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(watcher1.value).toBe(123)
|
expect(watcher1.value).toBe(123)
|
||||||
expect(watcher2.value).toBeUndefined()
|
expect(watcher2.value).toBeUndefined()
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
expect(spy).toHaveBeenCalledWith(123, undefined)
|
expect(spy).toHaveBeenCalledWith(123, undefined)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
@ -85,11 +85,11 @@ describe('Watcher', () => {
|
|||||||
vm.b = { c: [{ a: 1 }] }
|
vm.b = { c: [{ a: 1 }] }
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spy).toHaveBeenCalledWith(vm.b, oldB)
|
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
|
vm.b.c[0].a = 2
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
|
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
|
||||||
expect(spy.calls.count()).toBe(3)
|
expect(spy.mock.calls.length).toBe(3)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -110,11 +110,11 @@ describe('Watcher', () => {
|
|||||||
Vue.set(vm.b, '_', vm.b)
|
Vue.set(vm.b, '_', vm.b)
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
|
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
|
||||||
expect(spy.calls.count()).toBe(1)
|
expect(spy.mock.calls.length).toBe(1)
|
||||||
vm.b._.c = 1
|
vm.b._.c = 1
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
|
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -123,10 +123,10 @@ describe('Watcher', () => {
|
|||||||
Vue.set(vm.b, 'e', 123)
|
Vue.set(vm.b, 'e', 123)
|
||||||
waitForUpdate(() => {
|
waitForUpdate(() => {
|
||||||
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
|
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')
|
Vue.delete(vm.b, 'e')
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spy.calls.count()).toBe(2)
|
expect(spy.mock.calls.length).toBe(2)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ describe('invokeWithErrorHandling', () => {
|
|||||||
if (typeof Promise !== 'undefined') {
|
if (typeof Promise !== 'undefined') {
|
||||||
it('should errorHandler call once when nested calls return rejected promise', done => {
|
it('should errorHandler call once when nested calls return rejected promise', done => {
|
||||||
const originalHandler = Vue.config.errorHandler
|
const originalHandler = Vue.config.errorHandler
|
||||||
const handler = Vue.config.errorHandler = jasmine.createSpy()
|
const handler = Vue.config.errorHandler = vi.fn()
|
||||||
const userCatch = jasmine.createSpy()
|
const userCatch = vi.fn()
|
||||||
const err = new Error('fake error')
|
const err = new Error('fake error')
|
||||||
|
|
||||||
invokeWithErrorHandling(() => {
|
invokeWithErrorHandling(() => {
|
||||||
@ -15,7 +15,7 @@ describe('invokeWithErrorHandling', () => {
|
|||||||
})
|
})
|
||||||
}).catch(userCatch).then(() => {
|
}).catch(userCatch).then(() => {
|
||||||
Vue.config.errorHandler = originalHandler
|
Vue.config.errorHandler = originalHandler
|
||||||
expect(handler.calls.count()).toBe(1)
|
expect(handler.mock.calls.length).toBe(1)
|
||||||
expect(userCatch).toHaveBeenCalledWith(err)
|
expect(userCatch).toHaveBeenCalledWith(err)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -23,7 +23,7 @@ describe('nextTick', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returned Promise should resolve correctly vs callback', done => {
|
it('returned Promise should resolve correctly vs callback', done => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
nextTick(spy)
|
nextTick(spy)
|
||||||
nextTick().then(() => {
|
nextTick().then(() => {
|
||||||
expect(spy).toHaveBeenCalled()
|
expect(spy).toHaveBeenCalled()
|
||||||
|
@ -5,9 +5,9 @@ import VNode from 'core/vdom/vnode'
|
|||||||
describe('vdom directive module', () => {
|
describe('vdom directive module', () => {
|
||||||
it('should work', () => {
|
it('should work', () => {
|
||||||
const directive1 = {
|
const directive1 = {
|
||||||
bind: jasmine.createSpy('bind'),
|
bind: vi.fn(),
|
||||||
update: jasmine.createSpy('update'),
|
update: vi.fn(),
|
||||||
unbind: jasmine.createSpy('unbind')
|
unbind: vi.fn()
|
||||||
}
|
}
|
||||||
const vm = new Vue({ directives: { directive1 }})
|
const vm = new Vue({ directives: { directive1 }})
|
||||||
// create
|
// create
|
||||||
|
@ -3,17 +3,17 @@ import VNode from 'core/vdom/vnode'
|
|||||||
|
|
||||||
describe('vdom events module', () => {
|
describe('vdom events module', () => {
|
||||||
it('should attach event handler to element', () => {
|
it('should attach event handler to element', () => {
|
||||||
const click = jasmine.createSpy()
|
const click = vi.fn()
|
||||||
const vnode = new VNode('a', { on: { click }})
|
const vnode = new VNode('a', { on: { click }})
|
||||||
|
|
||||||
const elm = patch(null, vnode)
|
const elm = patch(null, vnode)
|
||||||
document.body.appendChild(elm)
|
document.body.appendChild(elm)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not duplicate the same listener', () => {
|
it('should not duplicate the same listener', () => {
|
||||||
const click = jasmine.createSpy()
|
const click = vi.fn()
|
||||||
const vnode1 = new VNode('a', { on: { click }})
|
const vnode1 = new VNode('a', { on: { click }})
|
||||||
const vnode2 = new VNode('a', { on: { click }})
|
const vnode2 = new VNode('a', { on: { click }})
|
||||||
|
|
||||||
@ -21,90 +21,90 @@ describe('vdom events module', () => {
|
|||||||
patch(vnode1, vnode2)
|
patch(vnode1, vnode2)
|
||||||
document.body.appendChild(elm)
|
document.body.appendChild(elm)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should update different listener', () => {
|
it('should update different listener', () => {
|
||||||
const click = jasmine.createSpy()
|
const click = vi.fn()
|
||||||
const click2 = jasmine.createSpy()
|
const click2 = vi.fn()
|
||||||
const vnode1 = new VNode('a', { on: { click }})
|
const vnode1 = new VNode('a', { on: { click }})
|
||||||
const vnode2 = new VNode('a', { on: { click: click2 }})
|
const vnode2 = new VNode('a', { on: { click: click2 }})
|
||||||
|
|
||||||
const elm = patch(null, vnode1)
|
const elm = patch(null, vnode1)
|
||||||
document.body.appendChild(elm)
|
document.body.appendChild(elm)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
expect(click2.calls.count()).toBe(0)
|
expect(click2.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
patch(vnode1, vnode2)
|
patch(vnode1, vnode2)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
expect(click2.calls.count()).toBe(1)
|
expect(click2.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should attach Array of multiple handlers', () => {
|
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 vnode = new VNode('a', { on: { click: [click, click] }})
|
||||||
|
|
||||||
const elm = patch(null, vnode)
|
const elm = patch(null, vnode)
|
||||||
document.body.appendChild(elm)
|
document.body.appendChild(elm)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(2)
|
expect(click.mock.calls.length).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should update Array of multiple handlers', () => {
|
it('should update Array of multiple handlers', () => {
|
||||||
const click = jasmine.createSpy()
|
const click = vi.fn()
|
||||||
const click2 = jasmine.createSpy()
|
const click2 = vi.fn()
|
||||||
const vnode1 = new VNode('a', { on: { click: [click, click2] }})
|
const vnode1 = new VNode('a', { on: { click: [click, click2] }})
|
||||||
const vnode2 = new VNode('a', { on: { click: [click] }})
|
const vnode2 = new VNode('a', { on: { click: [click] }})
|
||||||
|
|
||||||
const elm = patch(null, vnode1)
|
const elm = patch(null, vnode1)
|
||||||
document.body.appendChild(elm)
|
document.body.appendChild(elm)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
expect(click2.calls.count()).toBe(1)
|
expect(click2.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
patch(vnode1, vnode2)
|
patch(vnode1, vnode2)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(2)
|
expect(click.mock.calls.length).toBe(2)
|
||||||
expect(click2.calls.count()).toBe(1)
|
expect(click2.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should remove handlers that are no longer present', () => {
|
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 vnode1 = new VNode('a', { on: { click }})
|
||||||
const vnode2 = new VNode('a', {})
|
const vnode2 = new VNode('a', {})
|
||||||
|
|
||||||
const elm = patch(null, vnode1)
|
const elm = patch(null, vnode1)
|
||||||
document.body.appendChild(elm)
|
document.body.appendChild(elm)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
patch(vnode1, vnode2)
|
patch(vnode1, vnode2)
|
||||||
global.triggerEvent(elm, 'click')
|
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', () => {
|
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 vnode1 = new VNode('a', { on: { click: [click, click] }})
|
||||||
const vnode2 = new VNode('a', {})
|
const vnode2 = new VNode('a', {})
|
||||||
|
|
||||||
const elm = patch(null, vnode1)
|
const elm = patch(null, vnode1)
|
||||||
document.body.appendChild(elm)
|
document.body.appendChild(elm)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(2)
|
expect(click.mock.calls.length).toBe(2)
|
||||||
|
|
||||||
patch(vnode1, vnode2)
|
patch(vnode1, vnode2)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(2)
|
expect(click.mock.calls.length).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
// #4650
|
// #4650
|
||||||
it('should handle single -> array or array -> single handler changes', () => {
|
it('should handle single -> array or array -> single handler changes', () => {
|
||||||
const click = jasmine.createSpy()
|
const click = vi.fn()
|
||||||
const click2 = jasmine.createSpy()
|
const click2 = vi.fn()
|
||||||
const click3 = jasmine.createSpy()
|
const click3 = vi.fn()
|
||||||
const vnode0 = new VNode('a', { on: { click: click }})
|
const vnode0 = new VNode('a', { on: { click: click }})
|
||||||
const vnode1 = new VNode('a', { on: { click: [click, click2] }})
|
const vnode1 = new VNode('a', { on: { click: [click, click2] }})
|
||||||
const vnode2 = new VNode('a', { on: { click: click }})
|
const vnode2 = new VNode('a', { on: { click: click }})
|
||||||
@ -113,23 +113,23 @@ describe('vdom events module', () => {
|
|||||||
const elm = patch(null, vnode0)
|
const elm = patch(null, vnode0)
|
||||||
document.body.appendChild(elm)
|
document.body.appendChild(elm)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(1)
|
expect(click.mock.calls.length).toBe(1)
|
||||||
expect(click2.calls.count()).toBe(0)
|
expect(click2.mock.calls.length).toBe(0)
|
||||||
|
|
||||||
patch(vnode0, vnode1)
|
patch(vnode0, vnode1)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(2)
|
expect(click.mock.calls.length).toBe(2)
|
||||||
expect(click2.calls.count()).toBe(1)
|
expect(click2.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
patch(vnode1, vnode2)
|
patch(vnode1, vnode2)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(3)
|
expect(click.mock.calls.length).toBe(3)
|
||||||
expect(click2.calls.count()).toBe(1)
|
expect(click2.mock.calls.length).toBe(1)
|
||||||
|
|
||||||
patch(vnode2, vnode3)
|
patch(vnode2, vnode3)
|
||||||
global.triggerEvent(elm, 'click')
|
global.triggerEvent(elm, 'click')
|
||||||
expect(click.calls.count()).toBe(3)
|
expect(click.mock.calls.length).toBe(3)
|
||||||
expect(click2.calls.count()).toBe(2)
|
expect(click2.mock.calls.length).toBe(2)
|
||||||
expect(click3.calls.count()).toBe(1)
|
expect(click3.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -270,7 +270,7 @@ describe('vdom patch: edge cases', () => {
|
|||||||
|
|
||||||
// #6803
|
// #6803
|
||||||
it('backwards compat with checkbox code generated before 2.4', () => {
|
it('backwards compat with checkbox code generated before 2.4', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = vi.fn()
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
label: 'foobar',
|
label: 'foobar',
|
||||||
@ -339,7 +339,7 @@ describe('vdom patch: edge cases', () => {
|
|||||||
|
|
||||||
// #7294
|
// #7294
|
||||||
it('should cleanup component inline events on patch when no events are present', done => {
|
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({
|
const vm = new Vue({
|
||||||
data: { ok: true },
|
data: { ok: true },
|
||||||
template: `
|
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)
|
// sometimes we do need to tap into these internal hooks (e.g. in vue-router)
|
||||||
// so make sure it does work
|
// so make sure it does work
|
||||||
const inlineHookSpy = jasmine.createSpy('inlineInit')
|
const inlineHookSpy = vi.fn()
|
||||||
|
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
render (h) {
|
render (h) {
|
||||||
@ -409,7 +409,7 @@ describe('vdom patch: edge cases', () => {
|
|||||||
}).$mount()
|
}).$mount()
|
||||||
|
|
||||||
expect(vm.$el.textContent).toBe('FooBar')
|
expect(vm.$el.textContent).toBe('FooBar')
|
||||||
expect(inlineHookSpy.calls.count()).toBe(2)
|
expect(inlineHookSpy.mock.calls.length).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
// #9549
|
// #9549
|
||||||
|
Loading…
Reference in New Issue
Block a user