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