-
-
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
Get outer DOM node from composite component wrapper #679
Get outer DOM node from composite component wrapper #679
Conversation
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 good overall, assuming other collabs are 👍 on adding the feature
it('should return the outer most DOMComponent of the wrapper', () => { | ||
const wrapper = mount(<Test />); | ||
expect(wrapper.getDOMNode()).to.have.property('className', 'outer'); | ||
}); |
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.
let's also add a test that grabs the inner DOM node, so we have one test for "root", one for "not root", and one for "throws on multiples"
it('should return the outer most DOMComponent of the root wrapper', () => { | ||
const wrapper = mount(<Test />); | ||
expect(wrapper.getDOMNode()).to.have.property('className', 'outer'); | ||
}); |
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.
nbd but let's make sure there's newlines between all the it
s :-)
One of travis CI processes failed relating to |
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; could use a rebase down to one commit.
Will wait to merge until other collabs approve,
This also fixes #290 |
According to the React documentation findDOMNode can't be used on functional components, so this method cannot either. Two points:
|
Yes, i think we should add it as long as it throws when used on an SFC. |
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.
Please ensure that it throws when wrapping an SFC.
return this.single('getDOMNode', findDOMNode); | ||
return this.single('getDOMNode', (n) => { | ||
if (isFunctionalComponent(n)) { | ||
throw new Error('Method “getDOMNode” cannot be used on functional components.'); |
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.
This should probably be a TypeError
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; could still use a rebase down to a single commit
830b56e
to
27db1b0
Compare
I just learnt how to rebase/squash 👍 |
@christian-schulze awesome! it still looks like it's not rebased on latest master tho, fwiw. |
27db1b0
to
e466a7f
Compare
@ljharb rebased from latest master |
@nfcampos et al; feel free to merge when you're ready |
e466a7f
to
0d263bd
Compare
@christian-schulze would you mind rebasing before I merge this? |
0d263bd
to
fd2939b
Compare
No worries @nfcampos, rebased |
Thanks @christian-schulze! will merge as soon as build passes on travis :) |
@nfcampos Build is green ✅ |
Merged, thanks! |
As outlined in #623 and #446, implement
ReactWrapper#getDOMNode
which provides access to the outer most DOMComponent of a mounted composite component.If you are happy for this to exist, I will add api documentation.