Skip to content

Commit

Permalink
stop adding null string key when there is a ref
Browse files Browse the repository at this point in the history
  • Loading branch information
bdwain authored and ljharb committed Oct 12, 2017
1 parent 14dbaaf commit 8c21e40
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 49 deletions.
6 changes: 3 additions & 3 deletions packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function instanceToTree(inst) {
nodeType: 'host',
type: el.type,
props: el._store.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance.getDOMNode(),
rendered: values(children).map(instanceToTree),
Expand All @@ -86,7 +86,7 @@ function instanceToTree(inst) {
nodeType: 'class',
type: el.type,
props: el._store.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: instanceToTree(inst._renderedComponent),
Expand Down Expand Up @@ -174,7 +174,7 @@ class ReactThirteenAdapter extends EnzymeAdapter {
nodeType: 'class',
type: cachedNode.type,
props: cachedNode.props,
key: cachedNode.key,
key: cachedNode.key || undefined,
ref: cachedNode.ref,
instance: renderer._instance._instance,
rendered: elementToTree(output),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function elementToTree(el) {
nodeType: nodeTypeFromType(type),
type,
props,
key,
key: key || undefined,
ref,
instance: null,
rendered,
Expand Down
6 changes: 3 additions & 3 deletions packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function instanceToTree(inst) {
nodeType: 'host',
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: ReactDOM.findDOMNode(inst.getPublicInstance()) || null,
rendered: values(children).map(instanceToTree),
Expand All @@ -58,7 +58,7 @@ function instanceToTree(inst) {
nodeType: typeToNodeType(el.type),
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || null,
rendered: instanceToTree(inst._renderedComponent),
Expand Down Expand Up @@ -145,7 +145,7 @@ class ReactFifteenAdapter extends EnzymeAdapter {
nodeType: typeToNodeType(cachedNode.type),
type: cachedNode.type,
props: cachedNode.props,
key: cachedNode.key,
key: cachedNode.key || undefined,
ref: cachedNode.ref,
instance: renderer._instance._instance,
rendered: elementToTree(output),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function instanceToTree(inst) {
nodeType: nodeType(inst),
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: childrenFromInst(inst, el).map(instanceToTree),
Expand All @@ -69,7 +69,7 @@ function instanceToTree(inst) {
nodeType: nodeType(inst),
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: childrenFromInst(inst, el).map(instanceToTree),
Expand All @@ -80,7 +80,7 @@ function instanceToTree(inst) {
nodeType: nodeType(inst),
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: instanceToTree(inst._renderedComponent),
Expand All @@ -90,7 +90,7 @@ function instanceToTree(inst) {
nodeType: nodeType(inst),
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || null,
rendered: childrenFromInst(inst, el).map(instanceToTree),
Expand Down Expand Up @@ -175,7 +175,7 @@ class ReactFifteenFourAdapter extends EnzymeAdapter {
nodeType: compositeTypeToNodeType(renderer._instance._compositeType),
type: cachedNode.type,
props: cachedNode.props,
key: cachedNode.key,
key: cachedNode.key || undefined,
ref: cachedNode.ref,
instance: renderer._instance._instance,
rendered: elementToTree(output),
Expand Down
10 changes: 5 additions & 5 deletions packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function instanceToTree(inst) {
nodeType: nodeType(inst),
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: values(inst._renderedChildren).map(instanceToTree),
Expand All @@ -70,7 +70,7 @@ function instanceToTree(inst) {
nodeType: 'host',
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: childrenFromInst(inst, el).map(instanceToTree),
Expand All @@ -81,7 +81,7 @@ function instanceToTree(inst) {
nodeType: nodeType(inst),
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: instanceToTree(inst._renderedComponent),
Expand All @@ -91,7 +91,7 @@ function instanceToTree(inst) {
nodeType: nodeType(inst),
type: el.type,
props: el.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || null,
rendered: childrenFromInst(inst, el).map(instanceToTree),
Expand Down Expand Up @@ -176,7 +176,7 @@ class ReactFifteenAdapter extends EnzymeAdapter {
nodeType: compositeTypeToNodeType(renderer._instance._compositeType),
type: cachedNode.type,
props: cachedNode.props,
key: cachedNode.key,
key: cachedNode.key || undefined,
ref: cachedNode.ref,
instance: renderer._instance._instance,
rendered: elementToTree(output),
Expand Down
8 changes: 4 additions & 4 deletions packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function toTree(vnode) {
nodeType: 'class',
type: node.type,
props: { ...node.memoizedProps },
key: node.key,
key: node.key || undefined,
ref: node.ref,
instance: node.stateNode,
rendered: childrenToTree(node.child),
Expand All @@ -85,7 +85,7 @@ function toTree(vnode) {
nodeType: 'function',
type: node.type,
props: { ...node.memoizedProps },
key: node.key,
key: node.key || undefined,
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
Expand All @@ -99,7 +99,7 @@ function toTree(vnode) {
nodeType: 'host',
type: node.type,
props: { ...node.memoizedProps },
key: node.key,
key: node.key || undefined,
ref: node.ref,
instance: node.stateNode,
rendered: renderedNodes,
Expand Down Expand Up @@ -225,7 +225,7 @@ class ReactSixteenAdapter extends EnzymeAdapter {
nodeType: nodeTypeFromType(cachedNode.type),
type: cachedNode.type,
props: cachedNode.props,
key: cachedNode.key,
key: cachedNode.key || undefined,
ref: cachedNode.ref,
instance: renderer._instance,
rendered: elementToTree(output),
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-utils/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function elementToTree(el) {
nodeType: nodeTypeFromType(type),
type,
props,
key,
key: key || undefined,
ref,
instance: null,
rendered,
Expand Down

0 comments on commit 8c21e40

Please sign in to comment.