Skip to content

Commit

Permalink
New render optimization test
Browse files Browse the repository at this point in the history
  • Loading branch information
esamattis committed Sep 14, 2015
1 parent b627269 commit 5ed9f40
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1212,5 +1212,38 @@ describe('React', () => {
// store.dispatch({ type: 'APPEND', body: 'd'});
// expect(childMapStateInvokes).toBe(5);
});

it('should not render the wrapped component when mapState does not produce change', () => {
const store = createStore(stringBuilder);
let renderCalls = 0;
let mapStateCalls = 0;

@connect(() => {
mapStateCalls++;
return {}; // no change!
})
class Container extends Component {
render() {
renderCalls++;
return <Passthrough {...this.props} />;
}
}

TestUtils.renderIntoDocument(
<ProviderMock store={store}>
<Container />
</ProviderMock>
);

expect(renderCalls).toBe(1);
expect(mapStateCalls).toBe(2);

store.dispatch({ type: 'APPEND', body: 'a'});

// After store a change mapState has been called
expect(mapStateCalls).toBe(3);
// But render is not because it did not make any actual changes
expect(renderCalls).toBe(1);
});
});
});

0 comments on commit 5ed9f40

Please sign in to comment.