Skip to content

Commit cfc5a3e

Browse files
committedJul 8, 2018
[Fix] shallow/mount: default iterator should be iterable
1 parent 6a9492c commit cfc5a3e

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed
 

Diff for: ‎packages/enzyme-test-suite/test/ReactWrapper-spec.jsx

+20
Original file line numberDiff line numberDiff line change
@@ -4018,6 +4018,26 @@ describeWithDOM('mount', () => {
40184018
expect(c1).to.deep.equal(c);
40194019
expect(d1).to.deep.equal(d);
40204020
});
4021+
4022+
it('returns an iterable iterator', () => {
4023+
class Foo extends React.Component {
4024+
render() {
4025+
return (
4026+
<div>
4027+
<a href="#1">Hello</a>
4028+
<a href="#2">Hello</a>
4029+
<a href="#3">Hello</a>
4030+
<a href="#4">Hello</a>
4031+
</div>
4032+
);
4033+
}
4034+
}
4035+
const wrapper = mount(<Foo />);
4036+
4037+
const iter = wrapper[ITERATOR_SYMBOL]();
4038+
expect(iter).to.have.property(ITERATOR_SYMBOL).and.be.a('function');
4039+
expect(iter[ITERATOR_SYMBOL]()).to.equal(iter);
4040+
});
40214041
});
40224042

40234043
describe('.instance()', () => {

Diff for: ‎packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx

+20
Original file line numberDiff line numberDiff line change
@@ -4973,6 +4973,26 @@ describe('shallow', () => {
49734973
expect(c1).to.deep.equal(c);
49744974
expect(d1).to.deep.equal(d);
49754975
});
4976+
4977+
it('returns an iterable iterator', () => {
4978+
class Foo extends React.Component {
4979+
render() {
4980+
return (
4981+
<div>
4982+
<a href="#1">Hello</a>
4983+
<a href="#2">Hello</a>
4984+
<a href="#3">Hello</a>
4985+
<a href="#4">Hello</a>
4986+
</div>
4987+
);
4988+
}
4989+
}
4990+
const wrapper = shallow(<Foo />);
4991+
4992+
const iter = wrapper[ITERATOR_SYMBOL]();
4993+
expect(iter).to.have.property(ITERATOR_SYMBOL).and.be.a('function');
4994+
expect(iter[ITERATOR_SYMBOL]()).to.equal(iter);
4995+
});
49764996
});
49774997

49784998
describe('.getNodes()', () => {

Diff for: ‎packages/enzyme/src/ReactWrapper.js

+1
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ if (ITERATOR_SYMBOL) {
10621062
const iter = this[NODES][ITERATOR_SYMBOL]();
10631063
const adapter = getAdapter(this[OPTIONS]);
10641064
return {
1065+
[ITERATOR_SYMBOL]() { return this; },
10651066
next() {
10661067
const next = iter.next();
10671068
if (next.done) {

Diff for: ‎packages/enzyme/src/ShallowWrapper.js

+1
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,7 @@ if (ITERATOR_SYMBOL) {
12641264
const iter = this.getNodesInternal()[ITERATOR_SYMBOL]();
12651265
const adapter = getAdapter(this[OPTIONS]);
12661266
return {
1267+
[ITERATOR_SYMBOL]() { return this; },
12671268
next() {
12681269
const next = iter.next();
12691270
if (next.done) {

0 commit comments

Comments
 (0)
Please sign in to comment.