React adapter 16: portals and roots may render fragments#1710
React adapter 16: portals and roots may render fragments#1710ljharb merged 2 commits intoenzymejs:masterfrom
Conversation
| </React.Fragment> | ||
| ); | ||
|
|
||
| expect(wrapper).to.have.lengthOf(2); |
There was a problem hiding this comment.
can we add assertions that the wrapper has a p and a span?
300b91d to
22142ab
Compare
ljharb
left a comment
There was a problem hiding this comment.
I've rebased this, but the tests are failing, so it still needs some work.
I also added a commit that you can feel free to remove, it was a shot in the dark.
|
I removed the two shallow tests, i'm not sure why i added them in the first place. ShallowRenderer doesn't support mounting a Fragment, and a Portal doesn't make any sense, since it's a DOM specific element. |
| ); | ||
| if (!isStateful) { | ||
|
|
||
| if (!isStateful && typeof Component === 'function') { |
There was a problem hiding this comment.
This is just so we get a clearer error is a user tries to mount a Fragment or Portal, they will see the ShallowTestRenderer informative error instead of the much less clear "Component is not a function"
|
@jquense I'd actually added them, for test parity. We should be able to shallow-render a fragment and a Portal. |
|
I'm not sure what you want to do in this case, it doesn't make much sense to me to intentionally hobble the mount cases for parities sake in my mind. The main issue tho is that upstream shallow renderer does not allow it. Same is true for the new context types as well |
|
Hmm. I certainly don't want to limit what However, I also don't want to limit what |
|
I think we can probably get clever and hack something together but maybe we can split that into a new PR? The goal here was really to support selectors through these types deep in element tree not at the root. at moment the adapter assumes they can only render single children. The tests have sort of accidentally brought to light this inconsistency, but it's one that already exists, not one introduced by this PR |
8fd62dd to
f0e8ae5
Compare
f0e8ae5 to
30b7970
Compare
|
Thanks! Let's do those changes in a followup as you suggested. |
This matches what react-test-renderer does as well.