@@ -12,10 +12,11 @@ test('The AsyncComputed decorator defines async computed properties', t => {
12
12
@Component ( )
13
13
class TestComponent extends Vue {
14
14
@AsyncComputed ( )
15
- async shouldBeComputed ( ) {
15
+ async shouldBeComputed ( ) {
16
16
return 1
17
17
}
18
18
}
19
+
19
20
const vm = new TestComponent ( )
20
21
21
22
t . equal ( vm . shouldBeComputed , null )
@@ -32,11 +33,12 @@ test('The AsyncComputed decorator allows options on async computed properties',
32
33
33
34
@Component ( )
34
35
class TestComponent extends Vue {
35
- @AsyncComputed ( { lazy : true } )
36
- async shouldBeComputed ( ) {
36
+ @AsyncComputed ( { lazy : true } )
37
+ async shouldBeComputed ( ) {
37
38
return 1
38
39
}
39
40
}
41
+
40
42
const vm = new TestComponent ( )
41
43
42
44
t . equal ( vm . shouldBeComputed , null )
@@ -56,12 +58,13 @@ test('The AsyncComputed decorator can be applied to getter computed properties',
56
58
@Component ( )
57
59
class TestComponent extends Vue {
58
60
@AsyncComputed ( { default : 0 } )
59
- get shouldBeComputed ( ) {
61
+ get shouldBeComputed ( ) {
60
62
return new Promise ( resolve => {
61
63
resolve ( 1 )
62
64
} )
63
65
}
64
66
}
67
+
65
68
const vm = new TestComponent ( )
66
69
67
70
t . equal ( vm . shouldBeComputed , 0 )
@@ -72,3 +75,47 @@ test('The AsyncComputed decorator can be applied to getter computed properties',
72
75
t . equal ( vm . shouldBeComputed , 1 )
73
76
} )
74
77
} )
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