Skip to content
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

Recipe for testing with React #446

Closed
vadimdemedes opened this issue Jan 17, 2016 · 27 comments · Fixed by #747
Closed

Recipe for testing with React #446

vadimdemedes opened this issue Jan 17, 2016 · 27 comments · Fixed by #747

Comments

@vadimdemedes
Copy link
Contributor

No description provided.

@MoOx
Copy link

MoOx commented Feb 9, 2016

Also relevant #186

@MoOx
Copy link

MoOx commented Mar 9, 2016

I will be happy to handle that as soon as recent change in master are released, as well as a way to allow people to use fancy stuff like css modules in their code to test.

@jamestalmage
Copy link
Contributor

I think @kentcdodds may already have a good start on this. He's apparently been teaching AVA with React in class. Not sure if he's got time to make an actual PR, but given his extensive work in this area, it would be good if he was involved.

@MoOx
Copy link

MoOx commented Mar 9, 2016

Ok, just ping me if you need a hand. I am going to write a blog post or 2 about AVA and AVA with React/webpack loaders.

@jamestalmage
Copy link
Contributor

@MoOx - Not saying you shouldn't be the one to do the PR, just that @kentcdodds should be looped in.

Please let us know about your blog posts when they go live!

@MoOx
Copy link

MoOx commented Mar 9, 2016

I will (maybe even before, during post review) :)

@kentcdodds
Copy link
Contributor

as well as a way to allow people to use fancy stuff like css modules in their code to test.

AVA with React/webpack loaders.

If you can do webpack loaders in AVA tests, I want to see that. In my mind, this is a real challenge for any project using webpack heavily!

I'd love to review what you come up with :D

@adriantoine
Copy link
Contributor

To test with webpack loaders, there is this plugin: https://github.com/istarkov/babel-plugin-webpack-loaders, we use it for unit testing and backend rendering of react components using the css loader.

Has anyone considered using enzyme with ava?

@MoOx
Copy link

MoOx commented Mar 15, 2016

I use this exact babel plugin. Enzyme seems like going backward to me. jQuery syntax seriously? expect-jsx is clearly enough and make test very simple and clear.

@kentcdodds
Copy link
Contributor

I would recommend that the recipe only reference these abstractions but not actually use them. Just use the official React testing utils for the examples to give a good baseline and let other people choose what they'd prefer.

@kentcdodds
Copy link
Contributor

Also, I heard that using that plugin made things extremely slow. Has this been your experience?

@adriantoine
Copy link
Contributor

@MoOx do you have an example of using ava with expect-jsx? Sounds interesting

@MoOx
Copy link

MoOx commented Mar 15, 2016

@kentcdodds totally
@adriantoine #186 (comment)

@MoOx
Copy link

MoOx commented Mar 15, 2016

@kentcdodds It's slower because (for now I hope) you have to disable babel cache to don't miss update in css or any other files consumed by webpack that are not recognized by node/babel. You can subscribe to this thread if you are curious about how this will end :)
MoOx/phenomic#301

@kentcdodds
Copy link
Contributor

While we're on the subject of Webpack, what do you do about webpack aliases and custom modulesDirectories?

@MoOx
Copy link

MoOx commented Mar 15, 2016

I don't use those. I avoid webpack whenever I can. I only use it for loaders (transformation) and try to make my code reusable/universal.

@kentcdodds
Copy link
Contributor

That's a good way to go I think :)

@istarkov
Copy link

Babel plugin webpack supports aliases and modulesDirectories.

@kentcdodds
Copy link
Contributor

Babel plugin webpack

Just to be clear, you're talking about this one?

@istarkov
Copy link

Yes.

@sindresorhus
Copy link
Member

This looks interesting: https://twitter.com/bruderstein/status/718113603484823553

Plugin for unexpected to allow for testing the full virtual DOM, and against the shallow renderer

@MoOx
Copy link

MoOx commented Apr 8, 2016

Sounds a bit overkill to me. I am going to release some simple helpers (around 20 lines of code) and will let you know about it.

@kentcdodds
Copy link
Contributor

Yeah, I'd prefer to limit the number of abstractions in a recipe personally. Then just reference the other abstractions.

@MoOx
Copy link

MoOx commented Apr 8, 2016

I just published this small module https://github.com/MoOx/jsx-test-helpers

Code is simple https://github.com/MoOx/jsx-test-helpers/blob/master/src/index.js
And I pushed an annotated test file https://github.com/MoOx/jsx-test-helpers/blob/master/src/__tests__/index.js
Comments welcome.

For the webpack thing, I already pushed something on my js-boilerplate but I need to make a proper article about the entire setup.

@iam4x
Copy link

iam4x commented Apr 8, 2016

I adopted another solution using js-dom, enzyme and chai-enzyme:

and tests are written this way:

(my example has also CircleCI configuration with coverage)

@adriantoine
Copy link
Contributor

By the way, unexpected-react doesn't work with react@15 because it relies on react/addons which has been deprecated in react@0.14 and removed in react@15.

@adriantoine
Copy link
Contributor

and @MoOx solution works quite well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants