File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -3110,6 +3110,46 @@ describe('React', () => {
31103110 expect ( rendered . getByTestId ( 'child' ) . dataset . count ) . toEqual ( '3' )
31113111 expect ( rendered . getByTestId ( 'child' ) . dataset . prop ) . toEqual ( 'b' )
31123112 } )
3113+
3114+ it ( 'should invoke mapState always with latest store state' , ( ) => {
3115+ const store = createStore ( ( state = 0 ) => state + 1 )
3116+
3117+ let reduxCountPassedToMapState
3118+
3119+ @connect ( reduxCount => {
3120+ reduxCountPassedToMapState = reduxCount
3121+ return reduxCount < 2 ? { a : 'a' } : { a : 'b' }
3122+ } )
3123+ class InnerComponent extends Component {
3124+ render ( ) {
3125+ return < Passthrough { ...this . props } />
3126+ }
3127+ }
3128+
3129+ class OuterComponent extends Component {
3130+ constructor ( ) {
3131+ super ( )
3132+ this . state = { count : 0 }
3133+ }
3134+
3135+ render ( ) {
3136+ return < InnerComponent { ...this . state } />
3137+ }
3138+ }
3139+
3140+ let outerComponent
3141+ rtl . render (
3142+ < ProviderMock store = { store } >
3143+ < OuterComponent ref = { c => ( outerComponent = c ) } />
3144+ </ ProviderMock >
3145+ )
3146+
3147+ store . dispatch ( { type : '' } )
3148+ store . dispatch ( { type : '' } )
3149+ outerComponent . setState ( ( { count } ) => ( { count : count + 1 } ) )
3150+
3151+ expect ( reduxCountPassedToMapState ) . toEqual ( 3 )
3152+ } )
31133153 } )
31143154
31153155 it ( "should enforce top-down updates to ensure a deleted child's mapState doesn't throw errors" , ( ) => {
You can’t perform that action at this time.
0 commit comments