Skip to content

Commit

Permalink
[Refactor] mount/shallow: getElement: use this.single
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 2, 2018
1 parent 316a2c3 commit 6b63db3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
10 changes: 2 additions & 8 deletions packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ class ReactWrapper {
* @return {ReactElement}
*/
getElement() {
if (this.length !== 1) {
throw new Error('ReactWrapper::getElement() can only be called when wrapping one node');
}
return getAdapter(this[OPTIONS]).nodeToElement(this[NODE]);
return this.single('getElement', () => getAdapter(this[OPTIONS]).nodeToElement(this[NODE]));
}

/**
Expand Down Expand Up @@ -219,10 +216,7 @@ class ReactWrapper {
* @returns {ReactComponent|DOMComponent}
*/
instance() {
if (this.length !== 1) {
throw new Error('ReactWrapper::instance() can only be called on single nodes');
}
return this[NODE].instance;
return this.single('instance', () => this[NODE].instance);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ class ShallowWrapper {
* @return {ReactElement}
*/
getElement() {
if (this.length !== 1) {
throw new Error('ShallowWrapper::getElement() can only be called when wrapping one node');
}
return getAdapter(this[OPTIONS]).nodeToElement(this.getNodeInternal());
return this.single('getElement', n => getAdapter(this[OPTIONS]).nodeToElement(n));
}

/**
Expand Down

0 comments on commit 6b63db3

Please sign in to comment.