1
1
import _getMetaInfo from '../../src/shared/getMetaInfo'
2
- import { mount , loadVueMetaPlugin , vmTick } from '../utils'
2
+ import { mount , createWrapper , loadVueMetaPlugin , vmTick } from '../utils'
3
3
import { defaultOptions } from '../../src/shared/constants'
4
4
5
5
import GoodbyeWorld from '../components/goodbye-world.vue'
@@ -102,12 +102,26 @@ describe('client', () => {
102
102
103
103
test ( 'doesnt update when ssr attribute is set' , ( ) => {
104
104
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 } )
106
120
107
121
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 ( )
111
125
} )
112
126
113
127
test ( 'changed function is called' , async ( ) => {
@@ -203,9 +217,14 @@ describe('client', () => {
203
217
test ( 'changes before hydration initialization trigger an update' , async ( ) => {
204
218
html . setAttribute ( defaultOptions . ssrAttribute , 'true' )
205
219
220
+ const el = document . createElement ( 'div' )
221
+ el . setAttribute ( 'id' , 'app' )
222
+ el . setAttribute ( 'data-server-rendered' , true )
223
+ document . body . appendChild ( el )
224
+
206
225
// this component uses a computed prop to simulate a non-synchronous
207
226
// metaInfo update like you would have with a Vuex mutation
208
- const component = Vue . component ( 'test-component' , {
227
+ const Component = Vue . extend ( {
209
228
data ( ) {
210
229
return {
211
230
hiddenTheme : 'light'
@@ -229,20 +248,28 @@ describe('client', () => {
229
248
}
230
249
} )
231
250
232
- const wrapper = mount ( component , { localVue : Vue } )
251
+ const vm = new Component ( ) . $mount ( el )
252
+ const wrapper = createWrapper ( vm , { attachToDocument : true } )
233
253
expect ( html . getAttribute ( 'theme' ) ) . not . toBe ( 'dark' )
234
254
235
255
await vmTick ( wrapper . vm )
236
256
jest . runAllTimers ( )
237
257
238
258
expect ( html . getAttribute ( 'theme' ) ) . toBe ( 'dark' )
239
259
html . removeAttribute ( 'theme' )
260
+
261
+ wrapper . destroy ( )
240
262
} )
241
263
242
264
test ( 'changes during hydration initialization trigger an update' , async ( ) => {
243
265
html . setAttribute ( defaultOptions . ssrAttribute , 'true' )
244
266
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 ( {
246
273
data ( ) {
247
274
return {
248
275
hiddenTheme : 'light'
@@ -266,13 +293,16 @@ describe('client', () => {
266
293
}
267
294
} )
268
295
269
- const wrapper = mount ( component , { localVue : Vue } )
296
+ const vm = new Component ( ) . $mount ( el )
297
+ const wrapper = createWrapper ( vm , { attachToDocument : true } )
270
298
expect ( html . getAttribute ( 'theme' ) ) . not . toBe ( 'dark' )
271
299
272
300
await vmTick ( wrapper . vm )
273
301
jest . runAllTimers ( )
274
302
275
303
expect ( html . getAttribute ( 'theme' ) ) . toBe ( 'dark' )
276
304
html . removeAttribute ( 'theme' )
305
+
306
+ wrapper . destroy ( )
277
307
} )
278
308
} )
0 commit comments