diff --git a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
index cb43c28f4..1ec320fa5 100644
--- a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
+++ b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
@@ -3140,6 +3140,19 @@ describeWithDOM('mount', () => {
expect(wrapper.find('.bar').at(2).hasClass('bux')).to.equal(true);
expect(wrapper.find('.bar').at(3).hasClass('baz')).to.equal(true);
});
+
+ it('`.at()` does not affect the results of `.exists()`', () => {
+ const wrapper = mount((
+
+ ));
+ expect(wrapper.find('.bar').exists()).to.equal(false);
+ expect(wrapper.find('.bar').at(0).exists()).to.equal(false);
+
+ expect(wrapper.find('.foo').exists()).to.equal(true);
+ expect(wrapper.find('.foo').at(0).exists()).to.equal(true);
+ });
});
describe('.get(index)', () => {
diff --git a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
index b25d04854..58593e6ad 100644
--- a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
+++ b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
@@ -3091,6 +3091,19 @@ describe('shallow', () => {
expect(wrapper.find('.bar').at(2).hasClass('bux')).to.equal(true);
expect(wrapper.find('.bar').at(3).hasClass('baz')).to.equal(true);
});
+
+ it('`.at()` does not affect the results of `.exists()`', () => {
+ const wrapper = shallow((
+
+ ));
+ expect(wrapper.find('.bar').exists()).to.equal(false);
+ expect(wrapper.find('.bar').at(0).exists()).to.equal(false);
+
+ expect(wrapper.find('.foo').exists()).to.equal(true);
+ expect(wrapper.find('.foo').at(0).exists()).to.equal(true);
+ });
});
describe('.get(index)', () => {
diff --git a/packages/enzyme/src/ReactWrapper.js b/packages/enzyme/src/ReactWrapper.js
index 4c7387307..c0e3638f8 100644
--- a/packages/enzyme/src/ReactWrapper.js
+++ b/packages/enzyme/src/ReactWrapper.js
@@ -919,7 +919,11 @@ class ReactWrapper {
* @returns {ReactWrapper}
*/
at(index) {
- return this.wrap(this.getNodesInternal()[index]);
+ const nodes = this.getNodesInternal();
+ if (index < nodes.length) {
+ return this.wrap(nodes[index]);
+ }
+ return this.wrap([]);
}
/**
diff --git a/packages/enzyme/src/ShallowWrapper.js b/packages/enzyme/src/ShallowWrapper.js
index 00976ebc9..6d8c53708 100644
--- a/packages/enzyme/src/ShallowWrapper.js
+++ b/packages/enzyme/src/ShallowWrapper.js
@@ -1116,7 +1116,7 @@ class ShallowWrapper {
* @returns {ReactElement}
*/
get(index) {
- return getAdapter(this[OPTIONS]).nodeToElement(this.getNodesInternal()[index]);
+ return this.getElements()[index];
}
/**
@@ -1126,7 +1126,11 @@ class ShallowWrapper {
* @returns {ShallowWrapper}
*/
at(index) {
- return this.wrap(this.getNodesInternal()[index]);
+ const nodes = this.getNodesInternal();
+ if (index < nodes.length) {
+ return this.wrap(nodes[index]);
+ }
+ return this.wrap([]);
}
/**