File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 1
1
import identity from 'lodash/utility/identity' ;
2
2
import shallowEqual from '../utils/shallowEqual' ;
3
+ import isPlainObject from 'lodash/lang/isPlainObject' ;
4
+ import invariant from 'invariant' ;
3
5
4
6
export default function createConnector ( React ) {
5
7
const { Component, PropTypes } = React ;
@@ -59,6 +61,13 @@ export default function createConnector(React) {
59
61
selectState ( { context, props } = this ) {
60
62
const state = context . redux . getState ( ) ;
61
63
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
+
62
71
return { slice } ;
63
72
}
64
73
Original file line number Diff line number Diff line change @@ -144,5 +144,21 @@ describe('React', () => {
144
144
const div = TestUtils . findRenderedDOMComponentWithTag ( tree , 'div' ) ;
145
145
expect ( div . props . dispatch ) . toBe ( redux . dispatch ) ;
146
146
} ) ;
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 ( / s e l e c t / ) ;
162
+ } ) ;
147
163
} ) ;
148
164
} ) ;
You can’t perform that action at this time.
0 commit comments