diff --git a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js index 793b0c33e..49b798f12 100644 --- a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js +++ b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js @@ -218,6 +218,7 @@ function toTree(vnode) { }; } case FiberTags.ClassComponent: + case FiberTags.ClassComponentLazy: return { nodeType: 'class', type: node.type, @@ -228,6 +229,7 @@ function toTree(vnode) { rendered: childrenToTree(node.child), }; case FiberTags.FunctionalComponent: + case FiberTags.FunctionalComponentLazy: return { nodeType: 'function', type: node.type, diff --git a/packages/enzyme-adapter-react-16/src/detectFiberTags.js b/packages/enzyme-adapter-react-16/src/detectFiberTags.js index b59f79c41..955ee2c0d 100644 --- a/packages/enzyme-adapter-react-16/src/detectFiberTags.js +++ b/packages/enzyme-adapter-react-16/src/detectFiberTags.js @@ -51,12 +51,22 @@ module.exports = function detectFiberTags() { function Fn() { return null; } + function LazyFn() { + throw Promise.resolve(); + } // eslint-disable-next-line react/prefer-stateless-function class Cls extends React.Component { render() { return null; } } + // eslint-disable-next-line react/prefer-stateless-function + class LazyCls extends React.Component { + // eslint-disable-next-line react/require-render-return + render() { + throw Promise.resolve(); + } + } let Ctx = null; let FwdRef = null; let LazyComponent = null; @@ -75,8 +85,10 @@ module.exports = function detectFiberTags() { return { HostRoot: getFiber('test').return.return.tag, // Go two levels above to find the root ClassComponent: getFiber(React.createElement(Cls)).tag, + ClassComponentLazy: supportsSuspense ? getLazyFiber(LazyCls).tag : -1, Fragment: getFiber([['nested']]).tag, FunctionalComponent: getFiber(React.createElement(Fn)).tag, + FunctionalComponentLazy: supportsSuspense ? getLazyFiber(LazyFn).tag : -1, MemoSFC: supportsMemo ? getFiber(React.createElement(React.memo(Fn))).tag : -1, diff --git a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx index e61923683..c49403e1f 100644 --- a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx @@ -1321,6 +1321,55 @@ describeWithDOM('mount', () => { }); }); + describeIf(is('>= 16.6'), 'Suspense & lazy component', () => { + class Fallback extends React.Component { + render() { + return ( +