mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-23 18:50:34 +03:00
test: fix ssr hydration tests
This commit is contained in:
@@ -10,7 +10,7 @@ describe('basic browser with ssr page', () => {
|
|||||||
|
|
||||||
test('validate ssr', () => {
|
test('validate ssr', () => {
|
||||||
const htmlTag = html.match(/<html([^>]+)>/)[0]
|
const htmlTag = html.match(/<html([^>]+)>/)[0]
|
||||||
expect(htmlTag).toContain('data-vue-meta-server-rendered')
|
expect(htmlTag).toContain('data-vue-meta-server-rendered ')
|
||||||
expect(htmlTag).toContain(' lang="en" ')
|
expect(htmlTag).toContain(' lang="en" ')
|
||||||
expect(htmlTag).toContain(' amp ')
|
expect(htmlTag).toContain(' amp ')
|
||||||
expect(htmlTag).not.toContain('allowfullscreen')
|
expect(htmlTag).not.toContain('allowfullscreen')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import _getMetaInfo from '../../src/shared/getMetaInfo'
|
import _getMetaInfo from '../../src/shared/getMetaInfo'
|
||||||
import { mount, loadVueMetaPlugin, vmTick } from '../utils'
|
import { mount, createWrapper, loadVueMetaPlugin, vmTick } from '../utils'
|
||||||
import { defaultOptions } from '../../src/shared/constants'
|
import { defaultOptions } from '../../src/shared/constants'
|
||||||
|
|
||||||
import GoodbyeWorld from '../components/goodbye-world.vue'
|
import GoodbyeWorld from '../components/goodbye-world.vue'
|
||||||
@@ -102,12 +102,26 @@ describe('client', () => {
|
|||||||
|
|
||||||
test('doesnt update when ssr attribute is set', () => {
|
test('doesnt update when ssr attribute is set', () => {
|
||||||
html.setAttribute(defaultOptions.ssrAttribute, 'true')
|
html.setAttribute(defaultOptions.ssrAttribute, 'true')
|
||||||
const wrapper = mount(HelloWorld, { localVue: Vue })
|
|
||||||
|
const el = document.createElement('div')
|
||||||
|
el.setAttribute('id', 'app')
|
||||||
|
el.setAttribute('data-server-rendered', true)
|
||||||
|
document.body.appendChild(el)
|
||||||
|
|
||||||
|
const Component = Vue.extend({
|
||||||
|
metaInfo: { title: 'Test' },
|
||||||
|
render(h) {
|
||||||
|
return h('div', null, 'Test')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const vm = new Component().$mount(el)
|
||||||
|
const wrapper = createWrapper(vm, { attachToDocument: true })
|
||||||
|
|
||||||
const { tags } = wrapper.vm.$meta().refresh()
|
const { tags } = wrapper.vm.$meta().refresh()
|
||||||
// TODO: fix this test, not sure how to create a wrapper with a attri
|
expect(tags).toBe(false)
|
||||||
// bute data-server-rendered="true"
|
|
||||||
expect(tags).not.toBe(false)
|
wrapper.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('changed function is called', async () => {
|
test('changed function is called', async () => {
|
||||||
@@ -203,9 +217,14 @@ describe('client', () => {
|
|||||||
test('changes before hydration initialization trigger an update', async () => {
|
test('changes before hydration initialization trigger an update', async () => {
|
||||||
html.setAttribute(defaultOptions.ssrAttribute, 'true')
|
html.setAttribute(defaultOptions.ssrAttribute, 'true')
|
||||||
|
|
||||||
|
const el = document.createElement('div')
|
||||||
|
el.setAttribute('id', 'app')
|
||||||
|
el.setAttribute('data-server-rendered', true)
|
||||||
|
document.body.appendChild(el)
|
||||||
|
|
||||||
// this component uses a computed prop to simulate a non-synchronous
|
// this component uses a computed prop to simulate a non-synchronous
|
||||||
// metaInfo update like you would have with a Vuex mutation
|
// metaInfo update like you would have with a Vuex mutation
|
||||||
const component = Vue.component('test-component', {
|
const Component = Vue.extend({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
hiddenTheme: 'light'
|
hiddenTheme: 'light'
|
||||||
@@ -229,7 +248,8 @@ describe('client', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const wrapper = mount(component, { localVue: Vue })
|
const vm = new Component().$mount(el)
|
||||||
|
const wrapper = createWrapper(vm, { attachToDocument: true })
|
||||||
expect(html.getAttribute('theme')).not.toBe('dark')
|
expect(html.getAttribute('theme')).not.toBe('dark')
|
||||||
|
|
||||||
await vmTick(wrapper.vm)
|
await vmTick(wrapper.vm)
|
||||||
@@ -237,12 +257,19 @@ describe('client', () => {
|
|||||||
|
|
||||||
expect(html.getAttribute('theme')).toBe('dark')
|
expect(html.getAttribute('theme')).toBe('dark')
|
||||||
html.removeAttribute('theme')
|
html.removeAttribute('theme')
|
||||||
|
|
||||||
|
wrapper.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('changes during hydration initialization trigger an update', async () => {
|
test('changes during hydration initialization trigger an update', async () => {
|
||||||
html.setAttribute(defaultOptions.ssrAttribute, 'true')
|
html.setAttribute(defaultOptions.ssrAttribute, 'true')
|
||||||
|
|
||||||
const component = Vue.component('test-component', {
|
const el = document.createElement('div')
|
||||||
|
el.setAttribute('id', 'app')
|
||||||
|
el.setAttribute('data-server-rendered', true)
|
||||||
|
document.body.appendChild(el)
|
||||||
|
|
||||||
|
const Component = Vue.extend({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
hiddenTheme: 'light'
|
hiddenTheme: 'light'
|
||||||
@@ -266,7 +293,8 @@ describe('client', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const wrapper = mount(component, { localVue: Vue })
|
const vm = new Component().$mount(el)
|
||||||
|
const wrapper = createWrapper(vm, { attachToDocument: true })
|
||||||
expect(html.getAttribute('theme')).not.toBe('dark')
|
expect(html.getAttribute('theme')).not.toBe('dark')
|
||||||
|
|
||||||
await vmTick(wrapper.vm)
|
await vmTick(wrapper.vm)
|
||||||
@@ -274,5 +302,7 @@ describe('client', () => {
|
|||||||
|
|
||||||
expect(html.getAttribute('theme')).toBe('dark')
|
expect(html.getAttribute('theme')).toBe('dark')
|
||||||
html.removeAttribute('theme')
|
html.removeAttribute('theme')
|
||||||
|
|
||||||
|
wrapper.destroy()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
+3
-1
@@ -1,4 +1,4 @@
|
|||||||
import { mount, createLocalVue } from '@vue/test-utils'
|
import { mount, shallowMount, createWrapper, createLocalVue } from '@vue/test-utils'
|
||||||
import { renderToString } from '@vue/server-test-utils'
|
import { renderToString } from '@vue/server-test-utils'
|
||||||
import { defaultOptions } from '../../src/shared/constants'
|
import { defaultOptions } from '../../src/shared/constants'
|
||||||
import VueMetaBrowserPlugin from '../../src/browser'
|
import VueMetaBrowserPlugin from '../../src/browser'
|
||||||
@@ -6,6 +6,8 @@ import VueMetaServerPlugin from '../../src'
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
mount,
|
mount,
|
||||||
|
shallowMount,
|
||||||
|
createWrapper,
|
||||||
renderToString,
|
renderToString,
|
||||||
VueMetaBrowserPlugin,
|
VueMetaBrowserPlugin,
|
||||||
VueMetaServerPlugin
|
VueMetaServerPlugin
|
||||||
|
|||||||
Reference in New Issue
Block a user