Skip to content

Commit

Permalink
don't need to track initialNode separately
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbay committed Oct 24, 2016
1 parent 9172828 commit bcf175c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/ReactWrapper.jsx
Expand Up @@ -90,10 +90,8 @@ class ReactWrapper {
if (!nodes) {
this.initialNodes = [];
} else if (!Array.isArray(nodes)) {
this.initialNode = nodes;
this.initialNodes = [nodes];
} else {
this.initialNode = nodes[0];
this.initialNodes = nodes;
}
this.length = this.initialNodes.length;
Expand All @@ -112,7 +110,12 @@ class ReactWrapper {
* @return {ReactComponent}
*/
getNode() {
return this.initialNode || this.wrappedComponent;
if (this.length !== 1) {
throw new Error(
'ReactWrapper::getNode() can only be called when wrapping one node'
);
}
return this.initialNodes ? this.initialNodes[0] : this.wrappedComponent;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/ShallowWrapper.js
Expand Up @@ -90,10 +90,8 @@ class ShallowWrapper {
this.unrendered = null;
this.renderer = null;
if (!Array.isArray(nodes)) {
this.initialNode = nodes;
this.initialNodes = [nodes];
} else {
this.initialNode = nodes[0];
this.initialNodes = nodes;
}
this.length = this.initialNodes.length;
Expand All @@ -108,7 +106,12 @@ class ShallowWrapper {
* @return {ReactElement}
*/
getNode() {
return this.initialNode || this.renderer.getRenderOutput();
if (this.length !== 1) {
throw new Error(
'ShallowWrapper::getNode() can only be called when wrapping one node'
);
}
return this.initialNodes ? this.initialNodes[0] : this.renderer.getRenderOutput();
}

/**
Expand Down

0 comments on commit bcf175c

Please sign in to comment.