1- import { IS_PROXY , ProxyStateTree } from './'
1+ import { IS_PROXY , ProxyStateTree , StateModel } from './'
22
33describe ( 'CREATION' , ( ) => {
44 test ( 'should create a ProxyStateTree instance' , ( ) => {
@@ -126,7 +126,7 @@ describe('TrackMutationTree', () => {})
126126describe ( 'CLASSES' , ( ) => {
127127 describe ( 'ACCESS' , ( ) => {
128128 test ( 'should create proxy when accessed' , ( ) => {
129- class User {
129+ class User extends StateModel {
130130 name = 'Bob'
131131 }
132132 const state = {
@@ -139,7 +139,7 @@ describe('CLASSES', () => {
139139 } )
140140
141141 test ( 'should access properties' , ( ) => {
142- class User {
142+ class User extends StateModel {
143143 name = 'Bob'
144144 }
145145 const state = {
@@ -150,7 +150,7 @@ describe('CLASSES', () => {
150150 } )
151151
152152 test ( 'should track access properties' , ( ) => {
153- class User {
153+ class User extends StateModel {
154154 name = 'Bob'
155155 }
156156 const state = {
@@ -166,10 +166,33 @@ describe('CLASSES', () => {
166166 'user.name' ,
167167 ] )
168168 } )
169+
170+ test ( 'should track getters' , ( ) => {
171+ class User extends StateModel {
172+ private firstName = 'Bob'
173+ private lastName = 'Saget'
174+ get name ( ) {
175+ return this . firstName + ' ' + this . lastName
176+ }
177+ }
178+ const state = {
179+ user : new User ( )
180+ }
181+ const tree = new ProxyStateTree ( state )
182+ const trackStateTree = tree . getTrackStateTree ( ) . track ( ( ) => { } )
183+
184+ expect ( trackStateTree . state . user . name ) . toBe ( 'Bob Saget' )
185+
186+ expect ( Object . keys ( ( tree as any ) . pathDependencies ) ) . toEqual ( [
187+ 'user' ,
188+ 'user.firstName' ,
189+ 'user.lastName' ,
190+ ] )
191+ } )
169192 } )
170193 describe ( 'MUTATIONS' , ( ) => {
171194 test ( 'should throw when mutating without tracking' , ( ) => {
172- class User {
195+ class User extends StateModel {
173196 name = 'Bob'
174197 }
175198 const state = {
@@ -182,7 +205,7 @@ describe('CLASSES', () => {
182205 } )
183206
184207 test ( 'should throw if parts of state are nested' , ( ) => {
185- class User {
208+ class User extends StateModel {
186209 name = 'Bob'
187210 }
188211 const state = {
@@ -196,7 +219,7 @@ describe('CLASSES', () => {
196219 } )
197220 test ( 'should not notify changes to same value' , ( ) => {
198221 let renderCount = 0
199- class User {
222+ class User extends StateModel {
200223 name = 'Bob'
201224 }
202225 const state = {
@@ -221,7 +244,7 @@ describe('CLASSES', () => {
221244 expect ( renderCount ) . toBe ( 0 )
222245 } )
223246 test ( 'should track SET mutations' , ( ) => {
224- class User {
247+ class User extends StateModel {
225248 name = 'Bob'
226249 }
227250 const state = {
@@ -242,7 +265,7 @@ describe('CLASSES', () => {
242265 expect ( mutationTree . state . user . name ) . toBe ( 'bar2' )
243266 } )
244267 test ( 'should track mutations through methods' , ( ) => {
245- class User {
268+ class User extends StateModel {
246269 name = 'Bob'
247270 changeName ( ) {
248271 this . name = 'Bob2'
0 commit comments