@@ -1148,5 +1148,51 @@ describe('React', () => {
1148
1148
wrapper . setState ( { value : 1 } ) ;
1149
1149
expect ( target . props . statefulValue ) . toEqual ( 1 ) ;
1150
1150
} ) ;
1151
+
1152
+ it ( 'should not pass stale data to mapState' , ( ) => {
1153
+ const store = createStore ( stringBuilder ) ;
1154
+ store . dispatch ( { type : 'APPEND' , body : 'initial' } ) ;
1155
+ let childMapStateExecuted = false ;
1156
+
1157
+ @connect ( state => ( { string : state } ) )
1158
+ class Container extends Component {
1159
+
1160
+ emitChange ( ) {
1161
+ store . dispatch ( { type : 'APPEND' , body : 'changed' } ) ;
1162
+ }
1163
+
1164
+ render ( ) {
1165
+ return (
1166
+ < div >
1167
+ < button ref = "button" onClick = { this . emitChange . bind ( this ) } > change</ button >
1168
+ < ChildContainer parentString = { this . props . string } />
1169
+ </ div >
1170
+ ) ;
1171
+ }
1172
+ }
1173
+
1174
+ @connect ( ( state , parentProps ) => {
1175
+ childMapStateExecuted = true ;
1176
+ // The state from parent props should always be consistent with the current state
1177
+ expect ( state ) . toEqual ( parentProps . parentString ) ;
1178
+ return { } ;
1179
+ } )
1180
+ class ChildContainer extends Component {
1181
+ render ( ) {
1182
+ return < Passthrough { ...this . props } /> ;
1183
+ }
1184
+ }
1185
+
1186
+ const tree = TestUtils . renderIntoDocument (
1187
+ < ProviderMock store = { store } >
1188
+ < Container />
1189
+ </ ProviderMock >
1190
+ ) ;
1191
+
1192
+ const container = TestUtils . findRenderedComponentWithType ( tree , Container ) ;
1193
+ const node = React . findDOMNode ( container . getWrappedInstance ( ) . refs . button ) ;
1194
+ TestUtils . Simulate . click ( node ) ;
1195
+ expect ( childMapStateExecuted ) . toBe ( true ) ;
1196
+ } ) ;
1151
1197
} ) ;
1152
1198
} ) ;
0 commit comments