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 Sep 17, 2016
1 parent 79ac4a7 commit 663a552
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ export default 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 @@ -111,7 +109,12 @@ export default 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
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ export default 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 @@ -105,7 +103,12 @@ export default 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 663a552

Please sign in to comment.