Skip to content

Commit e033cac

Browse files
committed
Merge pull request #85 from rwillrich/throws-when-select-is-not-an-object
Throws an error when `select` not returns an object
2 parents ca935a1 + 98bf0f0 commit e033cac

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/components/createConnector.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import identity from 'lodash/utility/identity';
22
import shallowEqual from '../utils/shallowEqual';
3+
import isPlainObject from 'lodash/lang/isPlainObject';
4+
import invariant from 'invariant';
35

46
export default function createConnector(React) {
57
const { Component, PropTypes } = React;
@@ -59,6 +61,13 @@ export default function createConnector(React) {
5961
selectState({ context, props } = this) {
6062
const state = context.redux.getState();
6163
const slice = props.select(state);
64+
65+
invariant(
66+
isPlainObject(slice),
67+
'The return value of `select` prop must be an object. Instead received %s.',
68+
slice
69+
);
70+
6271
return { slice };
6372
}
6473

test/components/Connector.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,21 @@ describe('React', () => {
144144
const div = TestUtils.findRenderedDOMComponentWithTag(tree, 'div');
145145
expect(div.props.dispatch).toBe(redux.dispatch);
146146
});
147+
148+
it('should throw an error if `state` returns anything but a plain object', () => {
149+
const redux = createRedux(() => {});
150+
151+
expect(() => {
152+
TestUtils.renderIntoDocument(
153+
<Provider redux={redux}>
154+
{() => (
155+
<Connector state={() => 1}>
156+
{() => <div />}
157+
</Connector>
158+
)}
159+
</Provider>
160+
);
161+
}).toThrow(/select/);
162+
});
147163
});
148164
});

0 commit comments

Comments
 (0)