Skip to content

Throws an error when select not returns an object #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/components/createConnector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import identity from 'lodash/utility/identity';
import shallowEqual from '../utils/shallowEqual';
import isPlainObject from 'lodash/lang/isPlainObject';
import invariant from 'invariant';

export default function createConnector(React) {
const { Component, PropTypes } = React;
Expand Down Expand Up @@ -59,6 +61,13 @@ export default function createConnector(React) {
selectState({ context, props } = this) {
const state = context.redux.getState();
const slice = props.select(state);

invariant(
isPlainObject(slice),
'The return value of `select` prop must be an object. Instead received %s.',
slice
);

return { slice };
}

Expand Down
16 changes: 16 additions & 0 deletions test/components/Connector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,21 @@ describe('React', () => {
const div = TestUtils.findRenderedDOMComponentWithTag(tree, 'div');
expect(div.props.dispatch).toBe(redux.dispatch);
});

it('should throw an error if `state` returns anything but a plain object', () => {
const redux = createRedux(() => {});

expect(() => {
TestUtils.renderIntoDocument(
<Provider redux={redux}>
{() => (
<Connector state={() => 1}>
{() => <div />}
</Connector>
)}
</Provider>
);
}).toThrow(/select/);
});
});
});