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

Add method, tests, and docs for html method in ReactWrapper #71

Merged
merged 2 commits into from
Jan 14, 2016

Conversation

nfpiche
Copy link
Contributor

@nfpiche nfpiche commented Dec 12, 2015

Hope I was on the right track, this is for #31

@andersonba
Copy link

+1

* @returns {String}
*/
html() {
return this.single(n => findDOMNode(n).outerHTML.replace(/\sdata-reactid[^>]+/g, ''));
Copy link
Collaborator

Choose a reason for hiding this comment

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

how safe is this? if I understand correctly, this is assuming that the data-reactid attribute will be the last attribute of the node... how sure are we that this will be the case? A more robust regex might be good... or perhaps another approach to get this html?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that data-reactid will always be appended by react at the end. I can definitely dig into it a little more to make sure I'm correct. I agree a more robust regex might be better in the long run though, in addition to another test case where data-reactid is somewhere else in the HTML.

Thanks for the feedback! I should have an updated pull request sometime tonight.

@lelandrichardson
Copy link
Collaborator

This looks great other than my one comment. Thanks for contributing! I apologize for not getting to this sooner. I've been in the midst of a hackathon the past couple of days and haven't had much chance to look at this.

@nfpiche
Copy link
Contributor Author

nfpiche commented Dec 18, 2015

Hmm, not sure why that change would decrease the coverage, even .01%!

@lelandrichardson
Copy link
Collaborator

@nfpiche we've been having issues with the coveralls integration. It's producing some strange results... i wouldn't worry about it.

Regarding your change... i'm a bit worried about capturing data attributes other than data-reactid. It seems like there could be some reasonable react code that someone would add in data-react-foo attributes for compatibility with some other JS on the page, and they would want to see it in the rendered output.

I'm thinking we should limit it to just data-reactid for now?

* @returns {String}
*/
html() {
return this.single(n => findDOMNode(n).outerHTML.replace(/\sdata-react[-\w]+="[^"]+"+/g, ''));
Copy link
Collaborator

Choose a reason for hiding this comment

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

also, is the last + needed in this regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep good catch, not sure why I had that.

@nfpiche
Copy link
Contributor Author

nfpiche commented Dec 18, 2015

Yeah, changing it to catch just data-reactid is no problem.

I'm not 100% sure how to write a good test that show's it will delete the attribute we want from anywhere and leave the rest though. I tried adding my own data-reactid to a random place in the tag but react was obviously not thrilled about it :)

If you have a suggestion for a good way to test it I can implement it, but as it stands currently I've just been testing my regex here http://rubular.com/ and it seems to work as expected.

@nfpiche
Copy link
Contributor Author

nfpiche commented Dec 23, 2015

Oh now I see you prefer rebase over merge, not really familiar with doing a rebase, should I open a new pull request or did I rectify the rebase/merge difference in the next commit? Sorry for the confusion

@ljharb
Copy link
Member

ljharb commented Dec 23, 2015

@nfpiche please don't open a new PR - where "source" is a remote pointing to airbnb/enzyme, and assuming "origin" is a remote pointing to your fork: git checkout add-html-to-render && git fetch source && git rebase source/master and if all is well, git push -u -f origin add-html-to-render is the simplest rebase. you can add a -i to the rebase command to get an interactive prompt in your $EDITOR, which is a bit more complicated but allows you to combine commits.

@nfpiche
Copy link
Contributor Author

nfpiche commented Dec 24, 2015

went through those commands, hope this fixes it! sorry again for the confusion

@vesln
Copy link
Contributor

vesln commented Dec 24, 2015

awesome work!

@lelandrichardson
Copy link
Collaborator

@nfpiche this looks ready to merge now. Do you mind squashing your commits and rebasing so we can keep master's history clean?

@ljharb
Copy link
Member

ljharb commented Jan 7, 2016

(no need to squash down to one commit necessarily tho, just to a minimal set of conceptually atomic commits with meaningful commit messages :-) )

@blainekasten
Copy link
Contributor

This video is a good tutorial on squashing commits. https://asciinema.org/a/11269

@nfpiche
Copy link
Contributor Author

nfpiche commented Jan 10, 2016

I think this isn't terrible this time

Thanks for all the help everyone

* @returns {String}
*/
html() {
return this.single(n => findDOMNode(n).outerHTML.replace(/\sdata-reactid+="[^"]+"/g, ''));
Copy link
Member

Choose a reason for hiding this comment

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

if this is returning an actual dom node, would it make more sense to .cloneNode() it, and then removeAttribute('data-reactid'), and then .outerHTML?

Copy link
Collaborator

Choose a reason for hiding this comment

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

you'd have to remove data-reactid from EVERY node.

Copy link
Member

Choose a reason for hiding this comment

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

Array.prototype.forEach.call(findDomNode(n).querySelectorAll('[data-react-id]'), function (node) {
  node.removeAttribute('data-reactid');
});

seems like it'd be fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants