Skip to content

Commit

Permalink
New test 'should not render the wrapped component when mapState does …
Browse files Browse the repository at this point in the history
…not produce change'
  • Loading branch information
esamattis committed Sep 9, 2015
1 parent 8f5f825 commit 0225999
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 @@ -1147,5 +1147,38 @@ describe('React', () => {
wrapper.setState({ value: 1 });
expect(target.props.statefulValue).toEqual(1);
});

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(1);

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

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

0 comments on commit 0225999

Please sign in to comment.