-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Comments
Also relevant #186 |
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. |
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. |
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. |
@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! |
I will (maybe even before, during post review) :) |
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 |
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? |
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. |
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. |
Also, I heard that using that plugin made things extremely slow. Has this been your experience? |
@MoOx do you have an example of using ava with |
@kentcdodds totally |
@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 :) |
While we're on the subject of Webpack, what do you do about webpack aliases and custom |
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. |
That's a good way to go I think :) |
Babel plugin webpack supports aliases and modulesDirectories. |
Just to be clear, you're talking about this one? |
Yes. |
This looks interesting: https://twitter.com/bruderstein/status/718113603484823553
|
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. |
Yeah, I'd prefer to limit the number of abstractions in a recipe personally. Then just reference the other abstractions. |
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 For the webpack thing, I already pushed something on my js-boilerplate but I need to make a proper article about the entire setup. |
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) |
By the way, |
and @MoOx solution works quite well! |
No description provided.
The text was updated successfully, but these errors were encountered: