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 @@ -1147,5 +1147,38 @@ describe('React', () => {
1147
1147
wrapper . setState ( { value : 1 } ) ;
1148
1148
expect ( target . props . statefulValue ) . toEqual ( 1 ) ;
1149
1149
} ) ;
1150
+
1151
+ it ( 'should not render the wrapped component when mapState does not produce change' , ( ) => {
1152
+ const store = createStore ( stringBuilder ) ;
1153
+ let renderCalls = 0 ;
1154
+ let mapStateCalls = 0 ;
1155
+
1156
+ @connect ( ( ) => {
1157
+ mapStateCalls ++ ;
1158
+ return { } ; // no change!
1159
+ } )
1160
+ class Container extends Component {
1161
+ render ( ) {
1162
+ renderCalls ++ ;
1163
+ return < Passthrough { ...this . props } /> ;
1164
+ }
1165
+ }
1166
+
1167
+ TestUtils . renderIntoDocument (
1168
+ < ProviderMock store = { store } >
1169
+ < Container />
1170
+ </ ProviderMock >
1171
+ ) ;
1172
+
1173
+ expect ( renderCalls ) . toBe ( 1 ) ;
1174
+ expect ( mapStateCalls ) . toBe ( 1 ) ;
1175
+
1176
+ store . dispatch ( { type : 'APPEND' , body : 'a' } ) ;
1177
+
1178
+ // After store a change mapState has been called
1179
+ expect ( mapStateCalls ) . toBe ( 2 ) ;
1180
+ // But render is not because it did not make any actual changes
1181
+ expect ( renderCalls ) . toBe ( 1 ) ;
1182
+ } ) ;
1150
1183
} ) ;
1151
1184
} ) ;
You can’t perform that action at this time.
0 commit comments