Skip to content
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

update validation of component passed to the function returned by connect() #971

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -48,6 +48,7 @@
"invariant": "^2.2.4",
"loose-envify": "^1.1.0",
"prop-types": "^15.6.1",
"react-is": "^16.4.1",
"react-lifecycles-compat": "^3.0.0"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/components/connectAdvanced.js
@@ -1,6 +1,7 @@
import hoistStatics from 'hoist-non-react-statics'
import invariant from 'invariant'
import { Component, createElement } from 'react'
import * as ReactIs from 'react-is'

import Subscription from '../utils/Subscription'
import { storeShape, subscriptionShape } from '../utils/PropTypes'
Expand Down Expand Up @@ -88,7 +89,7 @@ export default function connectAdvanced(

return function wrapWithConnect(WrappedComponent) {
invariant(
typeof WrappedComponent == 'function',
ReactIs.isValidElementType(WrappedComponent),
`You must pass a component to the function returned by ` +
`${methodName}. Instead received ${JSON.stringify(WrappedComponent)}`
)
Expand Down
12 changes: 11 additions & 1 deletion test/components/connect.spec.js
Expand Up @@ -1206,6 +1206,16 @@ describe('React', () => {
)
})

it('should not throw an error if a object created with React.forwardRef is passed to the function returned by connect', () => {
const ForwardRefComponent = React.forwardRef((props, ref) =>
<div {...props} ref={ref} />
);

expect(() => {
connect()(ForwardRefComponent)
}).not.toThrow()
});

it('should throw an error if mapState, mapDispatch, or mergeProps returns anything but a plain object', () => {
const store = createStore(() => ({}))

Expand Down Expand Up @@ -1544,7 +1554,7 @@ describe('React', () => {

it('should throw an error if the store is not in the props or context', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})

class Container extends Component {
render() {
return <Passthrough />
Expand Down