-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
@@ -12,6 +12,10 @@ import { | |||
REACT15, | |||
} from './version'; | |||
|
|||
export const ITERATOR_SYMBOL = ( | |||
typeof Symbol === 'function' && Symbol.iterator | |||
) || '@@iterator'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid the complexity of having to conditionally define a method on a class when there's no Symbol.iterator
available, this falls back to '@@iterator'
. I don't think this should affect environments where neither is supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should absolutely not fall back to a string "@@iterator" unless it's the specific versions of Firefox where this imbues magic behavior - which can only be determined by using for..of
inside a Function
(so that the syntax doesn't break older engines).
@ljharb updated |
@@ -102,6 +103,26 @@ export default class ShallowWrapper { | |||
} | |||
|
|||
/** | |||
* Makes a wrapper iterable, which is useful when using destructive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aweary forgot to remove this i think
fb5220f
to
3dc1d30
Compare
|
||
|
||
if (ITERATOR_SYMBOL) { | ||
ReactWrapper.prototype[ITERATOR_SYMBOL] = function iterator() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i might be being over-pedantic here, but perhaps we should Object.defineProperty
this so it's non-enumerable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable enough to me
LGTM, but let's get a few more eyes on it |
This looks good to me as well |
can you rebase on latest master @aweary ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@ljharb unrelated to this PR, should we remove the LGTM integration now that Github has this approvals thing? |
@nfcampos probably, but for now let's keep it and just make sure to use "LGTM" in our approved reviews |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the Karma tests are failing.
@@ -3044,4 +3044,31 @@ describeWithDOM('mount', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
describe('@@iterator', () => { | |||
it('should be iterable', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these tests should be skipped when the environment lacks Symbols.
@@ -3585,4 +3585,31 @@ describe('shallow', () => { | |||
}); | |||
}); | |||
|
|||
describe('@@iterator', () => { | |||
it('should be iterable', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these tests should be skipped when the environment lacks Symbols.
@aweary i assume you'll plan to rebase to get rid of the merge commit? :-) |
@ljharb of course! 👍 |
73ffe26
to
3cf0488
Compare
@aweary do you want to look into the conflicts so that this can be merged? |
3cf0488
to
5b9022a
Compare
@nfcampos rebased 👍 |
Resolves #577
cc @ljharb