enzyme-adapter-react-16
Advanced tools
Comparing version 1.13.1 to 1.13.2
{ | ||
"name": "enzyme-adapter-react-16", | ||
"version": "1.13.1", | ||
"version": "1.13.2", | ||
"description": "JavaScript Testing utilities for React", | ||
@@ -45,3 +45,3 @@ "homepage": "http://airbnb.io/enzyme/", | ||
"react-test-renderer": "^16.0.0-0", | ||
"semver": "^5.6.0" | ||
"semver": "^5.7.0" | ||
}, | ||
@@ -60,3 +60,3 @@ "peerDependencies": { | ||
"eslint-config-airbnb": "^17.1.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-import": "^2.17.3", | ||
"eslint-plugin-jsx-a11y": "^6.2.1", | ||
@@ -63,0 +63,0 @@ "eslint-plugin-react": "^7.13.0", |
@@ -39,3 +39,3 @@ /* eslint no-use-before-define: 0 */ | ||
import { EnzymeAdapter } from 'enzyme'; | ||
import { typeOfNode } from 'enzyme/build/Utils'; | ||
import { typeOfNode, shallowEqual } from 'enzyme/build/Utils'; | ||
import { | ||
@@ -362,2 +362,9 @@ displayNameOfNode, | ||
function isStateful(Component) { | ||
return Component.prototype && ( | ||
Component.prototype.isReactComponent | ||
|| Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components | ||
); | ||
} | ||
class ReactSixteenAdapter extends EnzymeAdapter { | ||
@@ -472,3 +479,5 @@ constructor() { | ||
} | ||
eventFn(adapter.nodeToHostNode(node), mock); | ||
wrapAct(() => { | ||
eventFn(adapter.nodeToHostNode(node), mock); | ||
}); | ||
}, | ||
@@ -503,3 +512,42 @@ batchedUpdates(fn) { | ||
let wrappedComponent = null; | ||
const sentinel = {}; | ||
// wrap memo components with a PureComponent, or a class component with sCU | ||
const wrapPureComponent = (Component, compare) => { | ||
if (!is166) { | ||
throw new RangeError('this function should not be called in React < 16.6. Please report this!'); | ||
} | ||
if (lastComponent !== Component) { | ||
if (isStateful(Component)) { | ||
wrappedComponent = class extends Component {}; // eslint-disable-line react/prefer-stateless-function | ||
if (compare) { | ||
wrappedComponent.prototype.shouldComponentUpdate = nextProps => !compare(this.props, nextProps); | ||
} else { | ||
wrappedComponent.prototype.isPureReactComponent = true; | ||
} | ||
} else { | ||
let memoized = sentinel; | ||
let prevProps; | ||
wrappedComponent = function (props, ...args) { | ||
const shouldUpdate = memoized === sentinel || (compare | ||
? !compare(prevProps, props) | ||
: !shallowEqual(prevProps, props) | ||
); | ||
if (shouldUpdate) { | ||
memoized = Component({ ...Component.defaultProps, ...props }, ...args); | ||
prevProps = props; | ||
} | ||
return memoized; | ||
}; | ||
} | ||
Object.assign( | ||
wrappedComponent, | ||
Component, | ||
{ displayName: adapter.displayNameOfNode({ type: Component }) }, | ||
); | ||
lastComponent = Component; | ||
} | ||
return wrappedComponent; | ||
}; | ||
// Wrap functional components on versions prior to 16.5, | ||
@@ -514,2 +562,3 @@ // to avoid inadvertently pass a `this` instance to it. | ||
Component, | ||
{ displayName: adapter.displayNameOfNode({ type: Component }) }, | ||
); | ||
@@ -575,13 +624,10 @@ lastComponent = Component; | ||
const { type: Component } = renderedEl; | ||
const isStateful = Component.prototype && ( | ||
Component.prototype.isReactComponent | ||
|| Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components | ||
); | ||
const context = getMaskedContext(Component.contextTypes, unmaskedContext); | ||
if (!isStateful && isMemo(el.type)) { | ||
const InnerComp = el.type.type; | ||
if (isMemo(el.type)) { | ||
const { type: InnerComp, compare } = el.type; | ||
return withSetStateAllowed(() => renderer.render( | ||
{ ...el, type: wrapFunctionalComponent(InnerComp) }, | ||
{ ...el, type: wrapPureComponent(InnerComp, compare) }, | ||
context, | ||
@@ -591,3 +637,3 @@ )); | ||
if (!isStateful && typeof Component === 'function') { | ||
if (!isStateful(Component) && typeof Component === 'function') { | ||
return withSetStateAllowed(() => renderer.render( | ||
@@ -767,3 +813,6 @@ { ...renderedEl, type: wrapFunctionalComponent(Component) }, | ||
case ContextProvider || NaN: return 'ContextProvider'; | ||
case Memo || NaN: return displayNameOfNode(type); | ||
case Memo || NaN: { | ||
const nodeName = displayNameOfNode(node); | ||
return typeof nodeName === 'string' ? nodeName : `Memo(${displayNameOfNode(type)})`; | ||
} | ||
case ForwardRef || NaN: { | ||
@@ -770,0 +819,0 @@ if (type.displayName) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251045
2635
Updatedsemver@^5.7.0