-
Notifications
You must be signed in to change notification settings - Fork 83
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
Edge case with empty elements #6
Comments
Do you think you can write a test and submit it? Adding a new test is REALLY easy. Thanks for the bur report thought |
Done in #7 |
Both? I see one test |
The one added and the one just before it. |
Strangely your actual failing test in the issue description should work. But what you added can't. I chose to have a consistant resulting string because in the end when you compare JSX you won't have this issue. The added test case is not the one we are looking for I think. I will create a custom component rendering a |
So if you picture element is inserting line breaks inside the I am the only transforming But in your case, you do have line breaks in the render() so you should test for it. You could also implement toIncludeJSX as I did in expect-jsx: https://github.com/algolia/expect-jsx/blob/master/index.js#L22 It should remove the line breaks, not sure thought |
Maybe we could add an option to remove line breaks/whitespace from empty elements, happy to take a PR on this but unsure this is the right move (and it would be an option). |
The thing is: my render() {
return (
<div>
{
/* falsy thing */
}
</div>
)
} |
But in an html page, does it renders as |
It seems babel transform thinks it's the same to write |
So both line breaks and whitespace are working BUT <div>{false}</div> Is outputed as |
In your case it should be |
imo, we should not consider dfferences between |
Really what worries me is that there IS a difference: https://babeljs.io/repl/#?experimental=true&evaluate=true&loose=false&spec=false&code=var%20div%20%3D%20%3Cdiv%3E%7Bfalse%7D%3C%2Fdiv%3E%3B%0Avar%20div2%20%3D%20%3Cdiv%3E%7Bnull%7D%3C%2Fdiv%3E%3B I did not stumble on this usecase (wanting to assert {false} and ignoring whitespace). I would say that if there's nothing to display then maybe return null or nothing at all in your library. Otherwise happy to take a PR solving the |
fixed and released expect-jsx@2.1.1
|
Hmm seems like I will have to revert, weird edge cases again |
ok we should be good here now |
Thanks for you work. I will take a look to your fix when I will be back on my jsx test :) |
I am using
tape-jsx-equals
and have the following code(I only pasted the relevant part of my code)
The issue I get is:
The expected result I wrote is
<div></div>
, but somehow it got transformed to<div />
. Maybe by babel.Maybe
<div>{whitespace}</div>
should be rendered to<div />
?The text was updated successfully, but these errors were encountered: