diff --git a/src/components/connect.js b/src/components/connect.js index 3b60ebbce..e2dd4ce4f 100644 --- a/src/components/connect.js +++ b/src/components/connect.js @@ -53,6 +53,11 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps, const version = nextVersion++ return function wrapWithConnect(WrappedComponent) { + invariant( + typeof WrappedComponent == 'function', + `You must pass a component to the function returned by ` + + `connect. Instead received ${WrappedComponent}` + ) const connectDisplayName = `Connect(${getDisplayName(WrappedComponent)})` function checkStateShape(props, methodName) { diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js index 514eea018..2a42b4fb2 100644 --- a/test/components/connect.spec.js +++ b/test/components/connect.spec.js @@ -1017,6 +1017,12 @@ describe('React', () => { expect(stub.props.passVal).toBe('otherval') }) + it('should throw an error if a component is not passed to the function returned by connect', () => { + expect(connect()).toThrow( + /You must pass a component to the function/ + ) + }) + it('should throw an error if mapState, mapDispatch, or mergeProps returns anything but a plain object', () => { const store = createStore(() => ({}))