@@ -12,10 +12,11 @@ test('The AsyncComputed decorator defines async computed properties', t => {
1212 @Component ( )
1313 class TestComponent extends Vue {
1414 @AsyncComputed ( )
15- async shouldBeComputed ( ) {
15+ async shouldBeComputed ( ) {
1616 return 1
1717 }
1818 }
19+
1920 const vm = new TestComponent ( )
2021
2122 t . equal ( vm . shouldBeComputed , null )
@@ -32,11 +33,12 @@ test('The AsyncComputed decorator allows options on async computed properties',
3233
3334 @Component ( )
3435 class TestComponent extends Vue {
35- @AsyncComputed ( { lazy : true } )
36- async shouldBeComputed ( ) {
36+ @AsyncComputed ( { lazy : true } )
37+ async shouldBeComputed ( ) {
3738 return 1
3839 }
3940 }
41+
4042 const vm = new TestComponent ( )
4143
4244 t . equal ( vm . shouldBeComputed , null )
@@ -56,12 +58,13 @@ test('The AsyncComputed decorator can be applied to getter computed properties',
5658 @Component ( )
5759 class TestComponent extends Vue {
5860 @AsyncComputed ( { default : 0 } )
59- get shouldBeComputed ( ) {
61+ get shouldBeComputed ( ) {
6062 return new Promise ( resolve => {
6163 resolve ( 1 )
6264 } )
6365 }
6466 }
67+
6568 const vm = new TestComponent ( )
6669
6770 t . equal ( vm . shouldBeComputed , 0 )
@@ -72,3 +75,47 @@ test('The AsyncComputed decorator can be applied to getter computed properties',
7275 t . equal ( vm . shouldBeComputed , 1 )
7376 } )
7477} )
78+
79+
80+ test ( 'The AsyncComputed decorator works on getters with watch option' , t => {
81+ // t.plan(7)
82+
83+ @Component ( )
84+ class TestComponent extends Vue {
85+ watchValue = 'initial' ;
86+ computationCount = 0
87+
88+ @AsyncComputed ( { default : 'default' , watch : [ 'watchValue' ] , lazy : false } )
89+ get asyncGetter ( ) {
90+ this . computationCount ++ ;
91+ return new Promise ( resolve => {
92+ resolve ( this . watchValue )
93+ } )
94+ }
95+ }
96+
97+ const vm = new TestComponent ( )
98+
99+ t . equal ( vm . watchValue , 'initial' , 'initial watch value' )
100+ t . equal ( vm . computationCount , 1 , 'getter calculation is triggered immediately' )
101+ t . equal ( vm . asyncGetter , 'default' , 'initial asyncGetter value' )
102+ t . equal ( vm . computationCount , 1 , 'getter is cached during this tick' )
103+
104+ Vue . nextTick ( ( ) => {
105+ t . equal ( vm . asyncGetter , 'initial' , 'getter is updated on next tick' )
106+ t . equal ( vm . computationCount , 1 , 'getter is not recalculated' )
107+
108+ vm . watchValue = 'updated' // reactive set
109+ t . equals ( vm . asyncGetter , 'initial' , 'getter returns cached value after watched value changes' ) // reactive get
110+ t . equal ( vm . computationCount , 1 , 'no immediate recalculation after watched value changes' )
111+
112+ Vue . nextTick ( ( ) => {
113+ t . equal ( vm . computationCount , 2 , 'a recalculation is triggered on tick after watched value changes' )
114+ Vue . nextTick ( ( ) => {
115+ t . equal ( vm . asyncGetter , 'updated' , 'getter value is updated in the ticket after recalculation was triggered' )
116+ t . equal ( vm . computationCount , 2 , 'there were 2 calculations in total' )
117+ } )
118+ } )
119+ } )
120+ } )
121+
0 commit comments