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

[Fix] dive should pass along options from shallow #771

Merged
merged 1 commit into from
Jan 26, 2017

Conversation

blackpost38
Copy link
Contributor

I made it, could you check this source?

I only added a logic that merges options to dive()

refs: #770

@ljharb ljharb changed the title Fix #770 merge options [Fix] dive should pass along options from shallow Jan 13, 2017
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.

Thanks!

Just a few comments.

I'm also not sure if this is a patch or a minor - other collaborators' thoughts?

@@ -3,6 +3,7 @@ import flatten from 'lodash/flatten';
import unique from 'lodash/uniq';
import compact from 'lodash/compact';
import cheerio from 'cheerio';
import merge from 'lodash/merge';
Copy link
Member

Choose a reason for hiding this comment

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

we have object.assign available, please use that instead of adding a new dependency.

Copy link
Contributor Author

@blackpost38 blackpost38 Jan 13, 2017

Choose a reason for hiding this comment

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

I think we needs merge because options might be nested object.

// this.options === { context: {foo: 'hello'}};
// options === {context: {bar: 'enzyme!'}};
assign({}, this.options, options)  // It will be {context: {bar: 'enzyme!'}}

Copy link
Collaborator

Choose a reason for hiding this comment

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

deep merging the options sounds like too much, i think eg merging the context as in your example should be done manually by the user. thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think we want to avoid deep merging.

Copy link
Contributor Author

@blackpost38 blackpost38 Jan 16, 2017

Choose a reason for hiding this comment

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

oh, okay. i got it. I'll fix this and then send PR 😄
thanks for your feedbacks 👍

return this.single(name, (n) => {
if (isDOMComponentElement(n)) {
throw new TypeError(`ShallowWrapper::${name}() can not be called on DOM components`);
}
if (!isCustomComponentElement(n)) {
throw new TypeError(`ShallowWrapper::${name}() can only be called on components`);
}
return new ShallowWrapper(n, null, options);
return new ShallowWrapper(n, null, merge({}, originalOptions, options));
Copy link
Member

Choose a reason for hiding this comment

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

I think this can use this.options inline - the arrow function will ensure this is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right. okay, I'll fix it.

@nfcampos
Copy link
Collaborator

@ljharb this might be a major, no? it can break existing tests for components that depend on context being available/not available.

@ljharb
Copy link
Member

ljharb commented Jan 15, 2017

@nfcampos my thinking is that a component that expects context would never be used or tested without context - thus, what would be the use case for having a test that this change breaks?

This also will pass through the lifecycle flag, but we're planning to enable that by default in the next major anyways.

@blackpost38
Copy link
Contributor Author

I fixed it. I tried to apply your feedbacks.

Could you check it out? thanks!

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 - still not sure whether this is major, minor, or patch.

@nfcampos
Copy link
Collaborator

@ljharb only got to this now — ive been without internet at home for the better part of two weeks :( — thinking about this some more I could agree with this being a patch, arguably the previous behaviour was wrong, the expectation in react for a child to receive the same thing in context as its parent, what do you think?

@ljharb
Copy link
Member

ljharb commented Jan 25, 2017

I think I agree that it should be a patch.

@nfcampos
Copy link
Collaborator

nfcampos commented Jan 25, 2017

@blackpost38 do you mind rebasing this on latest master?

@blackpost38
Copy link
Contributor Author

@nfcampos It's done.

@nfcampos nfcampos merged commit c71ed62 into enzymejs:master Jan 26, 2017
@nfcampos
Copy link
Collaborator

Thanks @blackpost38 !

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.

4 participants