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

Conversation

aweary
Copy link
Collaborator

@aweary aweary commented Sep 12, 2016

Resolves #577

cc @ljharb

@@ -12,6 +12,10 @@ import {
REACT15,
} from './version';

export const ITERATOR_SYMBOL = (
typeof Symbol === 'function' && Symbol.iterator
) || '@@iterator';
Copy link
Collaborator Author

@aweary aweary Sep 12, 2016

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.

Copy link
Member

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).

@aweary
Copy link
Collaborator Author

aweary commented Sep 12, 2016

@ljharb updated

@@ -102,6 +103,26 @@ export default class ShallowWrapper {
}

/**
* Makes a wrapper iterable, which is useful when using destructive
Copy link
Collaborator

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



if (ITERATOR_SYMBOL) {
ReactWrapper.prototype[ITERATOR_SYMBOL] = 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.

i might be being over-pedantic here, but perhaps we should Object.defineProperty this so it's non-enumerable?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, good point

Copy link
Collaborator Author

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

@ljharb
Copy link
Member

ljharb commented Sep 12, 2016

LGTM, but let's get a few more eyes on it

@nfcampos
Copy link
Collaborator

This looks good to me as well

@nfcampos
Copy link
Collaborator

can you rebase on latest master @aweary ?

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

LGTM

@nfcampos
Copy link
Collaborator

@ljharb unrelated to this PR, should we remove the LGTM integration now that Github has this approvals thing?

@ljharb
Copy link
Member

ljharb commented Sep 14, 2016

@nfcampos probably, but for now let's keep it and just make sure to use "LGTM" in our approved reviews

@aweary
Copy link
Collaborator Author

aweary commented Sep 14, 2016

@ljharb @nfcampos updated with master 👍

(also, side note, these Github updates are awesome)

Copy link
Member

@ljharb ljharb left a 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', () => {
Copy link
Member

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', () => {
Copy link
Member

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.

@ljharb
Copy link
Member

ljharb commented Sep 14, 2016

@aweary i assume you'll plan to rebase to get rid of the merge commit? :-)

@aweary
Copy link
Collaborator Author

aweary commented Sep 14, 2016

@ljharb of course! 👍

@nfcampos
Copy link
Collaborator

nfcampos commented Oct 7, 2016

@aweary do you want to look into the conflicts so that this can be merged?

@aweary
Copy link
Collaborator Author

aweary commented Oct 11, 2016

@nfcampos rebased 👍

@nfcampos nfcampos merged commit 746eac4 into enzymejs:master Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants