Now that React is officially recommending people use react-testing-library, I wonder whether people would be in favor of including it by default. I made a video about what you need to do to add react-testing-library to create-react-app:
https://www.youtube.com/watch?v=Yx-p3irizCQ&list=PLV5CVI1eNcJgCrPH_e6d57KRUTiDZgs0u&t=60s
This commit is me adding the library and setup: https://github.com/kentcdodds/create-react-app-react-testing-library-example/commit/ad467aebee35f2ce040402658d3365c7c1f6335c
Note: In that commit and video I demo how to include
jest-domwhich I think would be good to include as well, but I have no problem if ya'll would prefer not to include that.
I'd love to see a :+1: if you're in favor and a :-1: if you're not. I promise to not tweet about this issue myself to avoid bringing unfair attention in my favor (though others can feel free to if they want :wink:).
Hey Kent. I think this would fit in nicely with #6270 as a template. What do you think?
I'm not sure what you mean. Are you suggesting this should be included in the -minimal template rather than the default? That seems counter-intuitive. I would assume that "minimal" would be as little as possible to make things work, and the default would have all the extra bells and whistles. Happy to have it included in any form though :)
Sorry I should have elaborated more. That PR I linked has morphed into a bigger idea of being able to create apps from a _template_. Templates could be published on npm and referenced using the create-react-app CLI via a specific param.
So for react-testing-library it could be something like create-react-app --use react-testing-library my-app, which would create the app from a template called react-testing-library containing the bits necessary to get the user going with react-testing-library including a best practice App.test.js file, dependencies, etc.
I'd be fine with that. I don't have time to work on it myself (I was just bringing up the idea). It does make sense that the default template would be very bare bones and people could opt-into things like a testing library and other features via flags. :+1:
Just yesterday, I created a sample app based on create-react-app with react-testing-library just so I could use it "by default" on any new project I create.
Jest by itself is not enough for ui tests. Create-react-app, as an opinionated project, could adopt react-testing-library either by default or by a flag.
The adding as template idea is good, but as @gustavobini says jest is really not enough for react testing and it would make sense to add as a default (because otherwise people will just use enzyme as there is years of articles and docs about it).
I'd like to bring this up again. It's been several months and we've seen a steady growth in the popularity of React Testing Library in that time, especially among newcomers who are desperately wanting to know how to test their apps. I say let's make this the default.
This sounds reasonable to me. I'd love to get some input from someone on the React team. Dan's on vacation. Maybe @bvaughn?
I know that @threepointone has expressed this is something he's interested in as well.