Skip to content

Commit cc5f049

Browse files
committed
New render optimization test
1 parent f0cd910 commit cc5f049

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/components/connect.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,5 +1193,38 @@ describe('React', () => {
11931193
TestUtils.Simulate.click(node);
11941194
expect(childMapStateExecuted).toBe(true);
11951195
});
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+
});
11961229
});
11971230
});

0 commit comments

Comments
 (0)