diff --git a/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js b/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js index dc2c14c3f..3fda84ac6 100644 --- a/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js +++ b/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js @@ -125,13 +125,16 @@ class ReactThirteenAdapter extends EnzymeAdapter { render(el, context, callback) { if (instance === null) { const { ref, type, props } = el; + const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); + const refProp = ReactWrapperComponent.supportsForwardedRef === true + ? 'forwardedRef' + : 'ref'; const wrapperProps = { Component: type, props, context, - ...(ref && { forwardedRef: ref }), + ...(ref && { [refProp]: ref }), }; - const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps); instance = React.render(wrappedEl, domNode); if (typeof callback === 'function') { diff --git a/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js b/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js index 0937ab84a..a1974a8d9 100644 --- a/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js +++ b/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js @@ -105,14 +105,17 @@ class ReactFourteenAdapter extends EnzymeAdapter { render(el, context, callback) { if (instance === null) { const { type, props, ref } = el; + const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); + const refProp = ReactWrapperComponent.supportsForwardedRef === true + ? 'forwardedRef' + : 'ref'; const wrapperProps = { Component: type, wrappingComponentProps: options.wrappingComponentProps, props, context, - ...(ref && { forwardedRef: ref }), + ...(ref && { [refProp]: ref }), }; - const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps); instance = ReactDOM.render(wrappedEl, domNode); if (typeof callback === 'function') { diff --git a/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js b/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js index 74d51c7ab..a615d8be4 100644 --- a/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js +++ b/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js @@ -140,14 +140,17 @@ class ReactFifteenFourAdapter extends EnzymeAdapter { render(el, context, callback) { if (instance === null) { const { type, props, ref } = el; + const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); + const refProp = ReactWrapperComponent.supportsForwardedRef === true + ? 'forwardedRef' + : 'ref'; const wrapperProps = { Component: type, wrappingComponentProps: options.wrappingComponentProps, props, context, - ...(ref && { forwardedRef: ref }), + ...(ref && { [refProp]: ref }), }; - const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps); instance = ReactDOM.render(wrappedEl, domNode); if (typeof callback === 'function') { diff --git a/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js b/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js index 469d6bf54..62a6f14a9 100644 --- a/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js +++ b/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js @@ -140,14 +140,17 @@ class ReactFifteenAdapter extends EnzymeAdapter { render(el, context, callback) { if (instance === null) { const { type, props, ref } = el; + const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); + const refProp = ReactWrapperComponent.supportsForwardedRef === true + ? 'forwardedRef' + : 'ref'; const wrapperProps = { Component: type, wrappingComponentProps: options.wrappingComponentProps, props, context, - ...(ref && { forwardedRef: ref }), + ...(ref && { [refProp]: ref }), }; - const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps); instance = ReactDOM.render(wrappedEl, domNode); if (typeof callback === 'function') { diff --git a/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js b/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js index aeee15fa9..674ee7c65 100644 --- a/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js +++ b/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js @@ -273,14 +273,17 @@ class ReactSixteenOneAdapter extends EnzymeAdapter { render(el, context, callback) { if (instance === null) { const { type, props, ref } = el; + const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); + const refProp = ReactWrapperComponent.supportsForwardedRef === true + ? 'forwardedRef' + : 'ref'; const wrapperProps = { Component: type, props, wrappingComponentProps, context, - ...(ref && { forwardedRef: ref }), + ...(ref && { [refProp]: ref }), }; - const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps); instance = hydrateIn ? ReactDOM.hydrate(wrappedEl, domNode) diff --git a/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js b/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js index 9333043c9..71646d111 100644 --- a/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js +++ b/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js @@ -275,14 +275,17 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter { render(el, context, callback) { if (instance === null) { const { type, props, ref } = el; + const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); + const refProp = ReactWrapperComponent.supportsForwardedRef === true + ? 'forwardedRef' + : 'ref'; const wrapperProps = { Component: type, props, wrappingComponentProps, context, - ...(ref && { forwardedRef: ref }), + ...(ref && { [refProp]: ref }), }; - const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps); instance = hydrateIn ? ReactDOM.hydrate(wrappedEl, domNode) diff --git a/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js b/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js index 4090e57d3..bcefac015 100644 --- a/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js +++ b/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js @@ -294,14 +294,17 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter { render(el, context, callback) { if (instance === null) { const { type, props, ref } = el; + const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); + const refProp = ReactWrapperComponent.supportsForwardedRef === true + ? 'forwardedRef' + : 'ref'; const wrapperProps = { Component: type, props, wrappingComponentProps, context, - ...(ref && { forwardedRef: ref }), + ...(ref && { [refProp]: ref }), }; - const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps); instance = hydrateIn ? ReactDOM.hydrate(wrappedEl, domNode) diff --git a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js index 2d0265706..97dcda029 100644 --- a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js +++ b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js @@ -404,14 +404,17 @@ class ReactSixteenAdapter extends EnzymeAdapter { return wrapAct(() => { if (instance === null) { const { type, props, ref } = el; + const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); + const refProp = ReactWrapperComponent.supportsForwardedRef === true + ? 'forwardedRef' + : 'ref'; const wrapperProps = { Component: type, props, wrappingComponentProps, context, - ...(ref && { forwardedRef: ref }), + ...(ref && { [refProp]: ref }), }; - const ReactWrapperComponent = createMountWrapper(el, { ...options, adapter }); const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps); instance = hydrateIn ? ReactDOM.hydrate(wrappedEl, domNode) diff --git a/packages/enzyme-adapter-utils/src/createMountWrapper.jsx b/packages/enzyme-adapter-utils/src/createMountWrapper.jsx index eafc53f2c..ff8f41c1c 100644 --- a/packages/enzyme-adapter-utils/src/createMountWrapper.jsx +++ b/packages/enzyme-adapter-utils/src/createMountWrapper.jsx @@ -106,6 +106,7 @@ export default function createMountWrapper(node, options = {}) { return component; } } + WrapperComponent.supportsForwardedRef = true; WrapperComponent.propTypes = { Component: makeValidElementType(adapter).isRequired, props: PropTypes.object.isRequired,