@@ -197,4 +197,80 @@ describe('client', () => {
197
197
guards . after ( )
198
198
expect ( afterNavigation ) . toHaveBeenCalled ( )
199
199
} )
200
+
201
+ test ( 'changes before hydration initialization trigger an update' , async ( ) => {
202
+ html . setAttribute ( defaultOptions . ssrAttribute , 'true' )
203
+
204
+ // this component uses a computed prop to simulate a non-synchronous
205
+ // metaInfo update like you would have with a Vuex mutation
206
+ const component = Vue . component ( 'test-component' , {
207
+ data ( ) {
208
+ return {
209
+ hiddenTheme : 'light'
210
+ }
211
+ } ,
212
+ computed : {
213
+ theme ( ) {
214
+ return this . hiddenTheme
215
+ }
216
+ } ,
217
+ beforeMount ( ) {
218
+ this . hiddenTheme = 'dark'
219
+ } ,
220
+ render : h => h ( 'div' ) ,
221
+ metaInfo ( ) {
222
+ return {
223
+ htmlAttrs : {
224
+ theme : this . theme
225
+ }
226
+ }
227
+ }
228
+ } )
229
+
230
+ const wrapper = mount ( component , { localVue : Vue } )
231
+ expect ( html . getAttribute ( 'theme' ) ) . not . toBe ( 'dark' )
232
+
233
+ await vmTick ( wrapper . vm )
234
+ jest . runAllTimers ( )
235
+
236
+ expect ( html . getAttribute ( 'theme' ) ) . toBe ( 'dark' )
237
+ html . removeAttribute ( 'theme' )
238
+ } )
239
+
240
+ test ( 'changes during hydration initialization trigger an update' , async ( ) => {
241
+ html . setAttribute ( defaultOptions . ssrAttribute , 'true' )
242
+
243
+ const component = Vue . component ( 'test-component' , {
244
+ data ( ) {
245
+ return {
246
+ hiddenTheme : 'light'
247
+ }
248
+ } ,
249
+ computed : {
250
+ theme ( ) {
251
+ return this . hiddenTheme
252
+ }
253
+ } ,
254
+ mounted ( ) {
255
+ this . hiddenTheme = 'dark'
256
+ } ,
257
+ render : h => h ( 'div' ) ,
258
+ metaInfo ( ) {
259
+ return {
260
+ htmlAttrs : {
261
+ theme : this . theme
262
+ }
263
+ }
264
+ }
265
+ } )
266
+
267
+ const wrapper = mount ( component , { localVue : Vue } )
268
+ expect ( html . getAttribute ( 'theme' ) ) . not . toBe ( 'dark' )
269
+
270
+ await vmTick ( wrapper . vm )
271
+ jest . runAllTimers ( )
272
+
273
+ expect ( html . getAttribute ( 'theme' ) ) . toBe ( 'dark' )
274
+ html . removeAttribute ( 'theme' )
275
+ } )
200
276
} )
0 commit comments