-
Notifications
You must be signed in to change notification settings - Fork 19
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
With react 16 <null> elements are breaking expectation #52
Comments
Thanks for reporting. The above is a pretty odd looking example, would it be possible to narrow it down a bit. From a quick scan it could look like it is the |
What do you get if you narrow it down to: class Component extends React.Component {
render() {
return (
<div>
<React.Fragment>
<h4>Headline 1</h4>
Text
</React.Fragment>
</div>
)
}
}
it('should render', function() {
expect(
<BadComponent />,
'to deeply render as',
<div>
<h4>Headline 1</h4>
Text
</div>
)
}) |
Hi, thanks for the fast response. The example looks that odd because I tried to mimic our quiet complex component. Since I did not knew what causes the issue I tried to reproduce what we do without doing a lot of things in between. I tried out your snippet, that one works just fine. So I tried out some other things and think I now know why the <div>
<React.Fragment>
<h4>Headline 1</h4>
Text
</React.Fragment>
</div> results in <Component>
<div>
<div>
<h4>Headline 1</h4>
Text
</div>
</div>
</Component> But <div>
<React.Fragment>
<h4>Headline 1</h4>
Text
</React.Fragment>
<h4>Headline 2</h4>
Text
</div> results in <Component>
<div>
<div>
<null>
<h4>Headline 1</h4>
Text
</null>
<h4>Headline 2</h4>
Text
</div>
</div>
</Component> That is also the reason I could not reproduce it for my lists. I forgot a part where we add a fixed element to the end of every list. const renderList = () => (
<List>
{() => (
<ol>
{['One', 'Two'].map(t => (
<ListItem key={t}>
<li>{t}</li>
</ListItem>
))}
<ListItem key={100}>
<li>Fixed list item</li>
</ListItem>
</ol>
)}
</List>
) will result in a <List>
<ol>
<null>
<ListItem>
<li>One</li>
</ListItem>
<ListItem>
<li>Two</li>
</ListItem>
</null>
<ListItem>
<li>Fixed list item</li>
</ListItem>
</ol>
</List> We could add the fixed list item to the array to fix the issue there. But then we still have the conditional |
Thanks that is a much better reproduction example. I'll have to pass it on to @bruderstein for a solution. |
So are there any news on this topic? I am currently fixing this issue by doing |
Thanks for the investigation and repro! I can reproduce, and am investigating the fix. |
@Raigen just a question on this - what would you prefer/expect here: WDYT? |
@bruderstein I would also expect it to flatten. |
Did anything happen with this? Some of my tests are having issues with this too. |
After the upgrade to react 16.3 and unexpected-react 5 some of our tests are breaking that where working before. In some cases there are strange
<null>
elements wrapping arrays of elements and the newFragment
.I was able to reproduce the issue partly with the following test case:
When I add the
null
element to the expected structure I get<null // should be <null
.When I add
React.Fragment
to the expected structure I get<null // should be <no-display-name
.It does not matter if I use array syntax as we had it before react 16, a method or Fragment, I tried all three of them as you can see at the commented out code. The result is the same.
In the original component I also get the
<null>
element where I have the<ListItem>
map, but I was not able to reproduce that in a simple way. It is a quite complex component. But when I understand what I have to do about thenull
element I will probably be able to fix the problem everywhere.The text was updated successfully, but these errors were encountered: