File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -1212,5 +1212,38 @@ describe('React', () => {
12121212 // store.dispatch({ type: 'APPEND', body: 'd'});
12131213 // expect(childMapStateInvokes).toBe(5);
12141214 } ) ;
1215+
1216+ it ( 'should not render the wrapped component when mapState does not produce change' , ( ) => {
1217+ const store = createStore ( stringBuilder ) ;
1218+ let renderCalls = 0 ;
1219+ let mapStateCalls = 0 ;
1220+
1221+ @connect ( ( ) => {
1222+ mapStateCalls ++ ;
1223+ return { } ; // no change!
1224+ } )
1225+ class Container extends Component {
1226+ render ( ) {
1227+ renderCalls ++ ;
1228+ return < Passthrough { ...this . props } /> ;
1229+ }
1230+ }
1231+
1232+ TestUtils . renderIntoDocument (
1233+ < ProviderMock store = { store } >
1234+ < Container />
1235+ </ ProviderMock >
1236+ ) ;
1237+
1238+ expect ( renderCalls ) . toBe ( 1 ) ;
1239+ expect ( mapStateCalls ) . toBe ( 2 ) ;
1240+
1241+ store . dispatch ( { type : 'APPEND' , body : 'a' } ) ;
1242+
1243+ // After store a change mapState has been called
1244+ expect ( mapStateCalls ) . toBe ( 3 ) ;
1245+ // But render is not because it did not make any actual changes
1246+ expect ( renderCalls ) . toBe ( 1 ) ;
1247+ } ) ;
12151248 } ) ;
12161249} ) ;
You can’t perform that action at this time.
0 commit comments