From e5e2a1fb3926d43c6fde207f4598759eb7ab5cd7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 13 Mar 2019 23:28:18 -0700 Subject: [PATCH] [enzyme-adapter-react-16] [fix] revert of wrapping shallow renders in TestUtils.act Partial revert of 35ec8fbb65fb755196fca1762ffcbe2f83733fc3 / #2034. --- .../src/ReactSixteenAdapter.js | 108 +++++++++--------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js index 6a002c9bd..76c2d5db9 100644 --- a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js +++ b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js @@ -396,65 +396,63 @@ class ReactSixteenAdapter extends EnzymeAdapter { let cachedNode = null; return { render(el, unmaskedContext) { - return wrapAct(() => { - cachedNode = el; - /* eslint consistent-return: 0 */ - if (typeof el.type === 'string') { - isDOM = true; - } else { - isDOM = false; - const { type: Component } = el; - - const isStateful = Component.prototype && ( - Component.prototype.isReactComponent - || Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components + cachedNode = el; + /* eslint consistent-return: 0 */ + if (typeof el.type === 'string') { + isDOM = true; + } else { + isDOM = false; + const { type: Component } = el; + + 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; + const wrappedEl = Object.assign( + (...args) => InnerComp(...args), // eslint-disable-line new-cap + InnerComp, ); + return withSetStateAllowed(() => renderer.render({ ...el, type: wrappedEl }, context)); + } - const context = getMaskedContext(Component.contextTypes, unmaskedContext); - - if (!isStateful && isMemo(el.type)) { - const InnerComp = el.type.type; - const wrappedEl = Object.assign( - (...args) => InnerComp(...args), // eslint-disable-line new-cap - InnerComp, - ); - return withSetStateAllowed(() => renderer.render({ ...el, type: wrappedEl }, context)); - } - - if (!isStateful && typeof Component === 'function') { - const wrappedEl = Object.assign( - (...args) => Component(...args), // eslint-disable-line new-cap - Component, - ); - return withSetStateAllowed(() => renderer.render({ ...el, type: wrappedEl }, context)); - } - if (isStateful) { - // fix react bug; see implementation of `getEmptyStateValue` - const emptyStateValue = getEmptyStateValue(); - if (emptyStateValue) { - Object.defineProperty(Component.prototype, 'state', { - configurable: true, - enumerable: true, - get() { - return null; - }, - set(value) { - if (value !== emptyStateValue) { - Object.defineProperty(this, 'state', { - configurable: true, - enumerable: true, - value, - writable: true, - }); - } - return true; - }, - }); - } + if (!isStateful && typeof Component === 'function') { + const wrappedEl = Object.assign( + (...args) => Component(...args), // eslint-disable-line new-cap + Component, + ); + return withSetStateAllowed(() => renderer.render({ ...el, type: wrappedEl }, context)); + } + if (isStateful) { + // fix react bug; see implementation of `getEmptyStateValue` + const emptyStateValue = getEmptyStateValue(); + if (emptyStateValue) { + Object.defineProperty(Component.prototype, 'state', { + configurable: true, + enumerable: true, + get() { + return null; + }, + set(value) { + if (value !== emptyStateValue) { + Object.defineProperty(this, 'state', { + configurable: true, + enumerable: true, + value, + writable: true, + }); + } + return true; + }, + }); } - return withSetStateAllowed(() => renderer.render(el, context)); } - }); + return withSetStateAllowed(() => renderer.render(el, context)); + } }, unmount() { renderer.unmount();