Skip to content

Commit 6b63db3

Browse files
committed
[Refactor] mount/shallow: getElement: use this.single
1 parent 316a2c3 commit 6b63db3

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

packages/enzyme/src/ReactWrapper.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ class ReactWrapper {
154154
* @return {ReactElement}
155155
*/
156156
getElement() {
157-
if (this.length !== 1) {
158-
throw new Error('ReactWrapper::getElement() can only be called when wrapping one node');
159-
}
160-
return getAdapter(this[OPTIONS]).nodeToElement(this[NODE]);
157+
return this.single('getElement', () => getAdapter(this[OPTIONS]).nodeToElement(this[NODE]));
161158
}
162159

163160
/**
@@ -219,10 +216,7 @@ class ReactWrapper {
219216
* @returns {ReactComponent|DOMComponent}
220217
*/
221218
instance() {
222-
if (this.length !== 1) {
223-
throw new Error('ReactWrapper::instance() can only be called on single nodes');
224-
}
225-
return this[NODE].instance;
219+
return this.single('instance', () => this[NODE].instance);
226220
}
227221

228222
/**

packages/enzyme/src/ShallowWrapper.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,7 @@ class ShallowWrapper {
273273
* @return {ReactElement}
274274
*/
275275
getElement() {
276-
if (this.length !== 1) {
277-
throw new Error('ShallowWrapper::getElement() can only be called when wrapping one node');
278-
}
279-
return getAdapter(this[OPTIONS]).nodeToElement(this.getNodeInternal());
276+
return this.single('getElement', n => getAdapter(this[OPTIONS]).nodeToElement(n));
280277
}
281278

282279
/**

0 commit comments

Comments
 (0)