-
Notifications
You must be signed in to change notification settings - Fork 17
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
Incomplete Mocha example? #24
Comments
Hi @pushred as I do not see any obvious issue causing this, could you create a reusable simple GIT repository where I could: npm install
npm test ? Thanks |
Thank you for the sanity check! I've pushed a reduction here: https://github.com/pushred/expect-jsx-mocha I included two test scripts to test both approaches Mocha's docs mention. In my case I'm using the JSX approach but I'm able to reproduce the issue with *.js all around as well, also tried a
|
Bit more context: to do the rendering I'm currently using this: https://github.com/MoOx/jsx-test-helpers/blob/master/src/index.js#L23 Using react-element-to-jsx-string directly actually didn't work, giving me a similar result like the above. So it seems I'm missing the shallow renderer that jsx-test-helpers adds, which gives me a working test where I can use the expect-jsx methods, though my diffs are not clean. Here's a test that fails because a single string in the component is different:
|
Not sure if the diff of child DOM components like in the above is supposed to be clean, it's working okay for single components. |
Thanks a lot for the deep investigation, after having a closer look it seems to be a misconception of what expect-jsx provides. In the test file ( Lines 32 to 38 in 919a766
div Hi! , we only do one level rendering testing.
Given what you want to do, you might get better results by just using http://facebook.github.io/jest/ We are not anymore using expect-jsx at Algolia, we only use Jest and snapshot rendering, which is what you are looking for. react-element-to-jsx-string is still a fun tool but I believe React testing tools are now able to do the same (see Jest snapshots testing). Let me know what you think. |
Ahh gotcha.. it's especially shallow. I'm using mocha at the moment because I'm working within an existing project and was trying to conform to it's existing test suite for the backend. Jest can do that of course but that'd be a bigger project. Snapshots have been a turnoff because of the noise they add to Git diffs (understood this is supposed to be a good thing) but I think I'll have to give it and Jest a shot if my components get much more complex. In other words I'll be using Jest in a week =) Thanks again, you've confirmed there's no magic I am missing! |
Really advising you to try again, once your components are a bit stable it's a joy. Noise in GIT |
Hi!
Apologies if this is a Mocha or expect issue but there's maybe some crucial missing information in the readme here, since Mocha is the example runner.
I wrote a test that essentially follows that example, but it doesn't work:
Yet the test component isn't rendering to a string:
Looking at the expect-jsx source I don't see any JSX handling specifically for the
expect
argument so I'm assuming the test source should be compiled before it's passed in. Per Mocha's readme I run the test with:If I inspect my component I see a React element:
So Mocha's compiler seems to work fine and
.toEqualJSX
is also working fine. It's unclear why the input remains the original JSX string rather than it's output.For now I am rendering the input separately, but the readme doesn't say anything about this..
The text was updated successfully, but these errors were encountered: