File tree 1 file changed +33
-0
lines changed 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -1193,5 +1193,38 @@ describe('React', () => {
1193
1193
TestUtils . Simulate . click ( node ) ;
1194
1194
expect ( childMapStateExecuted ) . toBe ( true ) ;
1195
1195
} ) ;
1196
+
1197
+ it ( 'should not render the wrapped component when mapState does not produce change' , ( ) => {
1198
+ const store = createStore ( stringBuilder ) ;
1199
+ let renderCalls = 0 ;
1200
+ let mapStateCalls = 0 ;
1201
+
1202
+ @connect ( ( ) => {
1203
+ mapStateCalls ++ ;
1204
+ return { } ; // no change!
1205
+ } )
1206
+ class Container extends Component {
1207
+ render ( ) {
1208
+ renderCalls ++ ;
1209
+ return < Passthrough { ...this . props } /> ;
1210
+ }
1211
+ }
1212
+
1213
+ TestUtils . renderIntoDocument (
1214
+ < ProviderMock store = { store } >
1215
+ < Container />
1216
+ </ ProviderMock >
1217
+ ) ;
1218
+
1219
+ expect ( renderCalls ) . toBe ( 1 ) ;
1220
+ expect ( mapStateCalls ) . toBe ( 1 ) ;
1221
+
1222
+ store . dispatch ( { type : 'APPEND' , body : 'a' } ) ;
1223
+
1224
+ // After store a change mapState has been called
1225
+ expect ( mapStateCalls ) . toBe ( 2 ) ;
1226
+ // But render is not because it did not make any actual changes
1227
+ expect ( renderCalls ) . toBe ( 1 ) ;
1228
+ } ) ;
1196
1229
} ) ;
1197
1230
} ) ;
You can’t perform that action at this time.
0 commit comments