mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 00:40:35 +03:00
test: fix unit tests
This commit is contained in:
@@ -8,11 +8,27 @@ Vue.use(VueMeta, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
export default function createApp () {
|
export default function createApp () {
|
||||||
|
const SomeComponent = {
|
||||||
|
name: 'SomeComponent',
|
||||||
|
template: `<div>
|
||||||
|
<p>Some Component</p>
|
||||||
|
</div>`,
|
||||||
|
mounted() {
|
||||||
|
console.log('some mounted')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Home = {
|
const Home = {
|
||||||
|
name: 'home',
|
||||||
|
components: {
|
||||||
|
SomeComponent
|
||||||
|
},
|
||||||
template: `<div>
|
template: `<div>
|
||||||
<router-link to="/about">About</router-link>
|
<router-link to="/about">About</router-link>
|
||||||
|
|
||||||
<p>Hello World</p>
|
<p>Hello World</p>
|
||||||
|
|
||||||
|
<some-component v-once></some-component>
|
||||||
</div>`,
|
</div>`,
|
||||||
metaInfo: {
|
metaInfo: {
|
||||||
title: 'Hello World',
|
title: 'Hello World',
|
||||||
@@ -32,6 +48,7 @@ export default function createApp () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const About = {
|
const About = {
|
||||||
|
name: 'About',
|
||||||
template: `<div>
|
template: `<div>
|
||||||
<router-link to="/">Home</router-link>
|
<router-link to="/">Home</router-link>
|
||||||
|
|
||||||
|
|||||||
@@ -72,35 +72,39 @@ describe('components', () => {
|
|||||||
expect(metaInfo.title).toEqual('Goodbye World')
|
expect(metaInfo.title).toEqual('Goodbye World')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('child meta-info removed when child is toggled', () => {
|
test('child meta-info removed when child is toggled', async () => {
|
||||||
const wrapper = mount(GoodbyeWorld, { localVue: Vue })
|
const wrapper = mount(GoodbyeWorld, { localVue: Vue })
|
||||||
|
|
||||||
let metaInfo = getMetaInfo(wrapper.vm)
|
let metaInfo = getMetaInfo(wrapper.vm)
|
||||||
expect(metaInfo.title).toEqual('Hello World')
|
expect(metaInfo.title).toEqual('Hello World')
|
||||||
|
|
||||||
wrapper.setData({ childVisible: false })
|
wrapper.setData({ childVisible: false })
|
||||||
|
await vmTick(wrapper.vm)
|
||||||
|
|
||||||
metaInfo = getMetaInfo(wrapper.vm)
|
metaInfo = getMetaInfo(wrapper.vm)
|
||||||
expect(metaInfo.title).toEqual('Goodbye World')
|
expect(metaInfo.title).toEqual('Goodbye World')
|
||||||
|
|
||||||
wrapper.setData({ childVisible: true })
|
wrapper.setData({ childVisible: true })
|
||||||
|
await vmTick(wrapper.vm)
|
||||||
|
|
||||||
metaInfo = getMetaInfo(wrapper.vm)
|
metaInfo = getMetaInfo(wrapper.vm)
|
||||||
expect(metaInfo.title).toEqual('Hello World')
|
expect(metaInfo.title).toEqual('Hello World')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('child meta-info removed when keep-alive child is toggled', () => {
|
test('child meta-info removed when keep-alive child is toggled', async () => {
|
||||||
const wrapper = mount(KeepAlive, { localVue: Vue })
|
const wrapper = mount(KeepAlive, { localVue: Vue })
|
||||||
|
|
||||||
let metaInfo = getMetaInfo(wrapper.vm)
|
let metaInfo = getMetaInfo(wrapper.vm)
|
||||||
expect(metaInfo.title).toEqual('Hello World')
|
expect(metaInfo.title).toEqual('Hello World')
|
||||||
|
|
||||||
wrapper.setData({ childVisible: false })
|
wrapper.setData({ childVisible: false })
|
||||||
|
await vmTick(wrapper.vm)
|
||||||
|
|
||||||
metaInfo = getMetaInfo(wrapper.vm)
|
metaInfo = getMetaInfo(wrapper.vm)
|
||||||
expect(metaInfo.title).toEqual('Alive World')
|
expect(metaInfo.title).toEqual('Alive World')
|
||||||
|
|
||||||
wrapper.setData({ childVisible: true })
|
wrapper.setData({ childVisible: true })
|
||||||
|
await vmTick(wrapper.vm)
|
||||||
|
|
||||||
metaInfo = getMetaInfo(wrapper.vm)
|
metaInfo = getMetaInfo(wrapper.vm)
|
||||||
expect(metaInfo.title).toEqual('Hello World')
|
expect(metaInfo.title).toEqual('Hello World')
|
||||||
@@ -230,6 +234,7 @@ describe('components', () => {
|
|||||||
expect(changed).toHaveBeenCalledTimes(1)
|
expect(changed).toHaveBeenCalledTimes(1)
|
||||||
|
|
||||||
wrapper.setData({ childVisible: true })
|
wrapper.setData({ childVisible: true })
|
||||||
|
await vmTick(wrapper.vm)
|
||||||
jest.runAllTimers()
|
jest.runAllTimers()
|
||||||
|
|
||||||
expect(changed).toHaveBeenCalledTimes(2)
|
expect(changed).toHaveBeenCalledTimes(2)
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ describe('plugin', () => {
|
|||||||
warn.mockRestore()
|
warn.mockRestore()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('updates can be pausing and resumed', async () => {
|
test('updates can be paused and resumed', async () => {
|
||||||
const { batchUpdate: _batchUpdate } = jest.requireActual('../../src/client/update')
|
const { batchUpdate: _batchUpdate } = jest.requireActual('../../src/client/update')
|
||||||
const batchUpdateSpy = batchUpdate.mockImplementation(_batchUpdate)
|
const batchUpdateSpy = batchUpdate.mockImplementation(_batchUpdate)
|
||||||
// because triggerUpdate & batchUpdate reside in the same file we cant mock them both,
|
// because triggerUpdate & batchUpdate reside in the same file we cant mock them both,
|
||||||
@@ -195,6 +195,7 @@ describe('plugin', () => {
|
|||||||
|
|
||||||
title = 'second title'
|
title = 'second title'
|
||||||
wrapper.setProps({ title })
|
wrapper.setProps({ title })
|
||||||
|
await vmTick(wrapper.vm)
|
||||||
|
|
||||||
// batchUpdate on normal update
|
// batchUpdate on normal update
|
||||||
expect(wrapper.vm.$root._vueMeta.initialized).toBe(true)
|
expect(wrapper.vm.$root._vueMeta.initialized).toBe(true)
|
||||||
@@ -206,6 +207,7 @@ describe('plugin', () => {
|
|||||||
wrapper.vm.$meta().pause()
|
wrapper.vm.$meta().pause()
|
||||||
title = 'third title'
|
title = 'third title'
|
||||||
wrapper.setProps({ title })
|
wrapper.setProps({ title })
|
||||||
|
await vmTick(wrapper.vm)
|
||||||
|
|
||||||
// no batchUpdate when pausing
|
// no batchUpdate when pausing
|
||||||
expect(wrapper.vm.$root._vueMeta.initialized).toBe(true)
|
expect(wrapper.vm.$root._vueMeta.initialized).toBe(true)
|
||||||
@@ -260,6 +262,8 @@ describe('plugin', () => {
|
|||||||
|
|
||||||
title = 'second title'
|
title = 'second title'
|
||||||
wrapper.setProps({ title })
|
wrapper.setProps({ title })
|
||||||
|
await vmTick(wrapper.vm)
|
||||||
|
|
||||||
jest.advanceTimersByTime(2)
|
jest.advanceTimersByTime(2)
|
||||||
expect(refreshSpy).not.toHaveBeenCalled()
|
expect(refreshSpy).not.toHaveBeenCalled()
|
||||||
jest.advanceTimersByTime(10)
|
jest.advanceTimersByTime(10)
|
||||||
|
|||||||
Reference in New Issue
Block a user