Skip to content

Commit

Permalink
[enzyme-adapter-react-16] [fix] properly render memoized SFCs
Browse files Browse the repository at this point in the history
Fixes #2038
  • Loading branch information
ljharb committed Apr 3, 2019
1 parent 487dc95 commit 4149a21
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
9 changes: 7 additions & 2 deletions packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,21 @@ function toTree(vnode) {
instance: node.stateNode,
rendered: childrenToTree(node.child.child),
};
case FiberTags.MemoSFC:
case FiberTags.MemoSFC: {
let renderedNodes = flatten(nodeAndSiblingsArray(node.child).map(toTree));
if (renderedNodes.length === 0) {
renderedNodes = [node.memoizedProps.children];
}
return {
nodeType: 'function',
type: node.elementType.type,
props: { ...node.memoizedProps },
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child.child),
rendered: renderedNodes,
};
}
case FiberTags.HostComponent: {
let renderedNodes = flatten(nodeAndSiblingsArray(node.child).map(toTree));
if (renderedNodes.length === 0) {
Expand Down
24 changes: 13 additions & 11 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -601,18 +601,20 @@ describeWithDOM('mount', () => {

const wrapper = mount(<Foo foo="qux" />);
expect(wrapper.debug()).to.equal(`<InnerFoo foo="qux">
<InnerComp>
<div>
<span>
Hello
</span>
<div>
<InnerComp>
<div>
<span>
Hello
</span>
</div>
</InnerComp>
<div className="bar">
bar
</div>
<div className="qoo">
qux
</div>
</InnerComp>
<div className="bar">
bar
</div>
<div className="qoo">
qux
</div>
</InnerFoo>`);
expect(wrapper.find('InnerComp')).to.have.lengthOf(1);
Expand Down
3 changes: 1 addition & 2 deletions packages/enzyme-test-suite/test/shared/methods/find.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,7 @@ export default function describeFind({
});

describeIf(is('>= 16.6'), 'React.memo', () => {
// FIXME: fix bug for mount
itIf(!isMount, 'works with an SFC', () => {
it('works with an SFC', () => {
const InnerComp = () => <div><span>Hello</span></div>;
const InnerFoo = ({ foo }) => (
<div>
Expand Down

0 comments on commit 4149a21

Please sign in to comment.