Skip to content

Commit

Permalink
[Fix] shallow/mount: default iterator should be iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 8, 2018
1 parent 6a9492c commit cfc5a3e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4018,6 +4018,26 @@ describeWithDOM('mount', () => {
expect(c1).to.deep.equal(c);
expect(d1).to.deep.equal(d);
});

it('returns an iterable iterator', () => {
class Foo extends React.Component {
render() {
return (
<div>
<a href="#1">Hello</a>
<a href="#2">Hello</a>
<a href="#3">Hello</a>
<a href="#4">Hello</a>
</div>
);
}
}
const wrapper = mount(<Foo />);

const iter = wrapper[ITERATOR_SYMBOL]();
expect(iter).to.have.property(ITERATOR_SYMBOL).and.be.a('function');
expect(iter[ITERATOR_SYMBOL]()).to.equal(iter);
});
});

describe('.instance()', () => {
Expand Down
20 changes: 20 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4973,6 +4973,26 @@ describe('shallow', () => {
expect(c1).to.deep.equal(c);
expect(d1).to.deep.equal(d);
});

it('returns an iterable iterator', () => {
class Foo extends React.Component {
render() {
return (
<div>
<a href="#1">Hello</a>
<a href="#2">Hello</a>
<a href="#3">Hello</a>
<a href="#4">Hello</a>
</div>
);
}
}
const wrapper = shallow(<Foo />);

const iter = wrapper[ITERATOR_SYMBOL]();
expect(iter).to.have.property(ITERATOR_SYMBOL).and.be.a('function');
expect(iter[ITERATOR_SYMBOL]()).to.equal(iter);
});
});

describe('.getNodes()', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ if (ITERATOR_SYMBOL) {
const iter = this[NODES][ITERATOR_SYMBOL]();
const adapter = getAdapter(this[OPTIONS]);
return {
[ITERATOR_SYMBOL]() { return this; },
next() {
const next = iter.next();
if (next.done) {
Expand Down
1 change: 1 addition & 0 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,7 @@ if (ITERATOR_SYMBOL) {
const iter = this.getNodesInternal()[ITERATOR_SYMBOL]();
const adapter = getAdapter(this[OPTIONS]);
return {
[ITERATOR_SYMBOL]() { return this; },
next() {
const next = iter.next();
if (next.done) {
Expand Down

0 comments on commit cfc5a3e

Please sign in to comment.