Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ReactWrapper and ShallowWrapper iterable #594

Merged
merged 5 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use Object.defineProperty so iterator is non-enumerable
  • Loading branch information
Brandon Dail authored and Brandon Dail committed Oct 11, 2016
commit 6cfb0d7f69dc3e4f27408cf0c6e5907ba887ddff
8 changes: 5 additions & 3 deletions src/ReactWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -912,9 +912,11 @@ class ReactWrapper {


if (ITERATOR_SYMBOL) {
ReactWrapper.prototype[ITERATOR_SYMBOL] = function iterator() {
return this.nodes[ITERATOR_SYMBOL]();
};
Object.defineProperty(ReactWrapper.prototype, ITERATOR_SYMBOL, {
value: function iterator() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configurable defaults to false, so we need to explicitly make it true here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why would we want it to be configurable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's just no reason to lock it down - someone might want to override it for their project, or something.

return this.nodes[ITERATOR_SYMBOL]();
},
});
}

export default ReactWrapper;
8 changes: 5 additions & 3 deletions src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,11 @@ class ShallowWrapper {
}

if (ITERATOR_SYMBOL) {
ShallowWrapper.prototype[ITERATOR_SYMBOL] = function iterator() {
return this.nodes[ITERATOR_SYMBOL]();
};
Object.defineProperty(ShallowWrapper.prototype, ITERATOR_SYMBOL, {
value: function iterator() {
return this.nodes[ITERATOR_SYMBOL]();
},
});
}

export default ShallowWrapper;