File tree Expand file tree Collapse file tree 1 file changed +58
-1
lines changed
Expand file tree Collapse file tree 1 file changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -404,6 +404,64 @@ test("shouldUpdate controls when to rerun the computation when a value changes",
404404 } )
405405} )
406406
407+ test ( "Watchers trigger but shouldUpdate can still block their updates" , t => {
408+ t . plan ( 6 )
409+ let i = 0
410+ const vm = new Vue ( {
411+ data : {
412+ canUpdate : true ,
413+ x : 0 ,
414+ y : 2 ,
415+ } ,
416+ asyncComputed : {
417+ z : {
418+ get ( ) {
419+ return Promise . resolve ( i + this . y )
420+ } ,
421+ watch ( ) {
422+ // eslint-disable-next-line no-unused-expressions
423+ this . x
424+ } ,
425+ shouldUpdate ( ) {
426+ return this . canUpdate
427+ }
428+ }
429+ }
430+ } )
431+ t . equal ( vm . z , null )
432+ Vue . nextTick ( ( ) => {
433+ t . equal ( vm . z , 2 )
434+ i ++
435+ vm . x --
436+ Vue . nextTick ( ( ) => {
437+ // This tick, Vue registers the change
438+ // in the watcher, and reevaluates
439+ // the getter function
440+ t . equal ( vm . z , 2 )
441+ Vue . nextTick ( ( ) => {
442+ // Now in this tick the promise has
443+ // resolved, and z is 3.
444+ t . equal ( vm . z , 3 )
445+ // We stop all updates from now on
446+ vm . canUpdate = false
447+ i ++
448+ vm . x --
449+ Vue . nextTick ( ( ) => {
450+ // This tick, Vue registers the change
451+ // in the watcher, and reevaluates
452+ // the getter function but no update
453+ t . equal ( vm . z , 3 )
454+ Vue . nextTick ( ( ) => {
455+ // Now in this tick the promise has
456+ // resolved, and z is still 3.
457+ t . equal ( vm . z , 3 )
458+ } )
459+ } )
460+ } )
461+ } )
462+ } )
463+ } )
464+
407465test ( "The default default value can be set in the plugin options" , t => {
408466 t . plan ( 2 )
409467 pluginOptions . default = 53
@@ -658,4 +716,3 @@ test("shouldUpdate works with lazy", t => {
658716 } )
659717 } )
660718} )
661-
You can’t perform that action at this time.
0 commit comments