Skip to content

Commit 0225999

Browse files
committed
New test 'should not render the wrapped component when mapState does not produce change'
1 parent 8f5f825 commit 0225999

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Diff for: test/components/connect.spec.js

+33
Original file line numberDiff line numberDiff line change
@@ -1147,5 +1147,38 @@ describe('React', () => {
11471147
wrapper.setState({ value: 1 });
11481148
expect(target.props.statefulValue).toEqual(1);
11491149
});
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+
});
11501183
});
11511184
});

0 commit comments

Comments
 (0)