@@ -29,6 +29,20 @@ const createTestFactories = () => {
2929 }
3030 } )
3131
32+ const ComputedFactory2 = types . model ( {
33+ props : types . map ( types . number ) ,
34+ get area ( ) {
35+ return this . props . get ( 'width' ) * this . props . get ( 'height' )
36+ }
37+ } , {
38+ setWidth ( value ) {
39+ this . props . set ( 'width' , value )
40+ } ,
41+ setHeight ( value ) {
42+ this . props . set ( 'height' , value )
43+ }
44+ } )
45+
3246 const BoxFactory = types . model ( {
3347 width : 0 ,
3448 height : 0
@@ -38,7 +52,7 @@ const createTestFactories = () => {
3852 color : "#FFFFFF"
3953 } )
4054
41- return { Factory, ComputedFactory, BoxFactory, ColorFactory}
55+ return { Factory, ComputedFactory, ComputedFactory2 , BoxFactory, ColorFactory}
4256}
4357
4458// === FACTORY TESTS ===
@@ -251,6 +265,16 @@ test("it should compose factories", (t) => {
251265 t . deepEqual ( getSnapshot ( ComposedFactory . create ( ) ) , { width : 0 , height : 0 , color : "#FFFFFF" } )
252266} )
253267
268+ test ( "it should compose factories with computed properties" , ( t ) => {
269+ const { ComputedFactory2, ColorFactory} = createTestFactories ( )
270+ const ComposedFactory = types . extend ( ColorFactory , ComputedFactory2 )
271+ const store = ComposedFactory . create ( { props : { width : 100 , height : 200 } } )
272+ t . deepEqual ( getSnapshot ( store ) , { props : { width : 100 , height : 200 } , color : "#FFFFFF" } )
273+ t . is ( store . area , 20000 )
274+ t . is ( typeof store . setWidth , 'function' )
275+ t . is ( typeof store . setHeight , 'function' )
276+ } )
277+
254278
255279// === TYPE CHECKS ===
256280test ( "it should check the type correctly" , ( t ) => {
0 commit comments