From c45bf1a665dcb2d0ee7fae44c9e296faaff59232 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Oct 2020 11:47:55 -0700 Subject: [PATCH] offscreencomponent wip --- packages/enzyme-adapter-react-17/package.json | 1 + .../src/ReactSeventeenAdapter.js | 12 ++++++++++++ .../enzyme-test-suite/test/ReactWrapper-spec.jsx | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/enzyme-adapter-react-17/package.json b/packages/enzyme-adapter-react-17/package.json index 0246806af..f816f58a5 100644 --- a/packages/enzyme-adapter-react-17/package.json +++ b/packages/enzyme-adapter-react-17/package.json @@ -45,6 +45,7 @@ "object.values": "^1.1.1", "prop-types": "^15.7.2", "react-is": "^17.0.0", + "react-reconciler": "^0.26.1", "react-test-renderer": "^17.0.0", "semver": "^5.7.0" }, diff --git a/packages/enzyme-adapter-react-17/src/ReactSeventeenAdapter.js b/packages/enzyme-adapter-react-17/src/ReactSeventeenAdapter.js index 62ebcc8c3..0e6913181 100644 --- a/packages/enzyme-adapter-react-17/src/ReactSeventeenAdapter.js +++ b/packages/enzyme-adapter-react-17/src/ReactSeventeenAdapter.js @@ -298,6 +298,18 @@ function toTree(vnode) { } case FiberTags.Lazy: return childrenToTree(node.child); + case FiberTags.OffscreenComponent: { + console.log(node.return.memoizedProps.children); + return { + nodeType: 'function', + type: Suspense, + props: { ...node.memoizedProps }, + key: ensureKeyOrUndefined(node.key), + ref: node.ref, + instance: null, + rendered: childrenToTree(nodeToHostNode(node.return.memoizedProps.children)), + }; + } default: throw new Error(`Enzyme Internal Error: unknown node with tag ${node.tag}`); } diff --git a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx index be671db8d..c77bf15ee 100644 --- a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx @@ -1111,7 +1111,8 @@ describeWithDOM('mount', () => { ); } } - it('finds Suspense and its children when no lazy component', () => { + + it.only('finds Suspense and its children when no lazy component', () => { class Component extends React.Component { render() { return ( @@ -1129,6 +1130,7 @@ describeWithDOM('mount', () => { const wrapper = mount(); expect(wrapper.is(SuspenseComponent)).to.equal(true); + console.log(wrapper.debug()); expect(wrapper.find(Component)).to.have.lengthOf(1); expect(wrapper.find(Fallback)).to.have.lengthOf(0); });