@@ -619,3 +619,56 @@ test('computed properties operate against their original store state', () => {
619619 expect ( stateAtAPointInTime . count ) . toBe ( 1 ) ;
620620 expect ( store . getState ( ) . count ) . toBe ( 2 ) ;
621621} ) ;
622+
623+ test ( 'issue #873: computed properties without state resolvers update when they have dependencies that depend on store state' , ( ) => {
624+ // ARRANGE
625+ const store = createStore ( {
626+ foo : {
627+ status : 'Ok' ,
628+ setStatus : action ( ( state , payload ) => {
629+ state . status = payload ;
630+ } )
631+ } ,
632+ bar : {
633+ status : 'Ok' ,
634+ setStatus : action ( ( state , payload ) => {
635+ state . status = payload ;
636+ } )
637+ } ,
638+ baz : {
639+ errorMessage : computed (
640+ [
641+ ( _ , storeState ) => storeState . foo . status ,
642+ ( _ , storeState ) => storeState . bar . status
643+ ] ,
644+ ( fooStatus , barStatus ) => {
645+ if ( fooStatus === 'Error' || barStatus === 'Error' ) {
646+ return 'Uh oh, error in app!' ;
647+ }
648+
649+ return '' ;
650+ }
651+ ) ,
652+ hasError : computed ( ( state ) => Boolean ( state . errorMessage ) )
653+ }
654+ } ) ;
655+
656+ let state = store . getState ( ) ;
657+
658+ // ASSERT
659+ expect ( state . foo . status ) . toBe ( 'Ok' ) ;
660+ expect ( state . bar . status ) . toBe ( 'Ok' ) ;
661+ expect ( state . baz . errorMessage ) . toBe ( '' ) ;
662+ expect ( state . baz . hasError ) . toBe ( false ) ;
663+
664+ // ACT
665+ store . getActions ( ) . foo . setStatus ( 'Error' ) ;
666+
667+ state = store . getState ( ) ;
668+
669+ // ASSERT
670+ expect ( state . foo . status ) . toBe ( 'Error' ) ;
671+ expect ( state . bar . status ) . toBe ( 'Ok' ) ;
672+ expect ( state . baz . errorMessage ) . toBe ( 'Uh oh, error in app!' ) ;
673+ expect ( state . baz . hasError ) . toBe ( true ) ; // would have failed before #874
674+ } ) ;
0 commit comments