11import _getMetaInfo from '../../src/shared/getMetaInfo'
2- import { mount , loadVueMetaPlugin , vmTick } from '../utils'
2+ import { mount , createWrapper , loadVueMetaPlugin , vmTick } from '../utils'
33import { defaultOptions } from '../../src/shared/constants'
44
55import GoodbyeWorld from '../components/goodbye-world.vue'
@@ -102,12 +102,26 @@ describe('client', () => {
102102
103103 test ( 'doesnt update when ssr attribute is set' , ( ) => {
104104 html . setAttribute ( defaultOptions . ssrAttribute , 'true' )
105- const wrapper = mount ( HelloWorld , { localVue : Vue } )
105+
106+ const el = document . createElement ( 'div' )
107+ el . setAttribute ( 'id' , 'app' )
108+ el . setAttribute ( 'data-server-rendered' , true )
109+ document . body . appendChild ( el )
110+
111+ const Component = Vue . extend ( {
112+ metaInfo : { title : 'Test' } ,
113+ render ( h ) {
114+ return h ( 'div' , null , 'Test' )
115+ }
116+ } )
117+
118+ const vm = new Component ( ) . $mount ( el )
119+ const wrapper = createWrapper ( vm , { attachToDocument : true } )
106120
107121 const { tags } = wrapper . vm . $meta ( ) . refresh ( )
108- // TODO: fix this test, not sure how to create a wrapper with a attri
109- // bute data-server-rendered="true"
110- expect ( tags ) . not . toBe ( false )
122+ expect ( tags ) . toBe ( false )
123+
124+ wrapper . destroy ( )
111125 } )
112126
113127 test ( 'changed function is called' , async ( ) => {
@@ -203,9 +217,14 @@ describe('client', () => {
203217 test ( 'changes before hydration initialization trigger an update' , async ( ) => {
204218 html . setAttribute ( defaultOptions . ssrAttribute , 'true' )
205219
220+ const el = document . createElement ( 'div' )
221+ el . setAttribute ( 'id' , 'app' )
222+ el . setAttribute ( 'data-server-rendered' , true )
223+ document . body . appendChild ( el )
224+
206225 // this component uses a computed prop to simulate a non-synchronous
207226 // metaInfo update like you would have with a Vuex mutation
208- const component = Vue . component ( 'test-component' , {
227+ const Component = Vue . extend ( {
209228 data ( ) {
210229 return {
211230 hiddenTheme : 'light'
@@ -229,20 +248,28 @@ describe('client', () => {
229248 }
230249 } )
231250
232- const wrapper = mount ( component , { localVue : Vue } )
251+ const vm = new Component ( ) . $mount ( el )
252+ const wrapper = createWrapper ( vm , { attachToDocument : true } )
233253 expect ( html . getAttribute ( 'theme' ) ) . not . toBe ( 'dark' )
234254
235255 await vmTick ( wrapper . vm )
236256 jest . runAllTimers ( )
237257
238258 expect ( html . getAttribute ( 'theme' ) ) . toBe ( 'dark' )
239259 html . removeAttribute ( 'theme' )
260+
261+ wrapper . destroy ( )
240262 } )
241263
242264 test ( 'changes during hydration initialization trigger an update' , async ( ) => {
243265 html . setAttribute ( defaultOptions . ssrAttribute , 'true' )
244266
245- const component = Vue . component ( 'test-component' , {
267+ const el = document . createElement ( 'div' )
268+ el . setAttribute ( 'id' , 'app' )
269+ el . setAttribute ( 'data-server-rendered' , true )
270+ document . body . appendChild ( el )
271+
272+ const Component = Vue . extend ( {
246273 data ( ) {
247274 return {
248275 hiddenTheme : 'light'
@@ -266,13 +293,16 @@ describe('client', () => {
266293 }
267294 } )
268295
269- const wrapper = mount ( component , { localVue : Vue } )
296+ const vm = new Component ( ) . $mount ( el )
297+ const wrapper = createWrapper ( vm , { attachToDocument : true } )
270298 expect ( html . getAttribute ( 'theme' ) ) . not . toBe ( 'dark' )
271299
272300 await vmTick ( wrapper . vm )
273301 jest . runAllTimers ( )
274302
275303 expect ( html . getAttribute ( 'theme' ) ) . toBe ( 'dark' )
276304 html . removeAttribute ( 'theme' )
305+
306+ wrapper . destroy ( )
277307 } )
278308} )
0 commit comments