3 ms·
See also Enzyme, a testing library specifically for React, that allows you to easy assert on both deep and shallow renders of the React DOM. https://github.com
by jitl 10y ago
See also Enzyme, a testing library specifically for React, that allows you to easy assert on both deep and shallow renders of the React DOM.
https://github.com/airbnb/enzyme#basic-usage https://github.com/airbnb/enzyme#basic-usage
- jfdk 10y agoWe haven't tried Enzyme, but we tend to prefer not adding more JS tools when we don't need to. JS is already a land of wayyyy too many tools and minimizing when possible can be a huge advantage when onboarding new devs onto a project. Also the DOM api is actually pretty simple to use when it comes to traversing the DOM. No need for "jQuery mimicking." Keep it simple.
- bgxor 10y agoI would really encourage you to give it a try. The "jQuery mimicking" is actually not even its best feature. I didn't think much of it at the beginning, but it pretty much makes React's test utils really pleasant to work with. All in all, it basically codifies and gives a reusable api to most of what you say in your gist.
- Klathmon 10y agoThis is a bit off topic, but why such aversion to purpose built tools in JS land? In my experience it's much harder to onboard devs to a custom-ish process than it is to hand them a purpose built tool with proper documentation and lots of examples of real-world usage to learn from. I tend to try to use already made tools over doing it myself* as it makes onboarding easier, lightens my cognitive load, reduces my testing surface, and is generally quicker than coming up with my own solution. * A bit of a disclaimer... I mean well made, well tested, and well supported tools taking into account the time cost of doing it myself, the complexity of the tool, how important/ingrained it will be in my application, the number of contributors in the project, the test coverage of the project, the speed/ease it can be switched out, how well it actually solves my problem at hand, and a ton of other things. I do not mean that you should blindly use every tools you can whenever possible, or that you should use it because Facebook/Google/Other-Company uses it.
- jfdk 10y agoWhat I should have said is "minimize tools when it makes sense" rather than "when possible." There are some tools that are more trouble than they're worth (for example, I feel this strongly about Jest). Enzyme isn't necessarily one of those, like I said I haven't used it, but I also haven't found a need to. Some abstractions over TestUtils' event simulation would certainly be valuable. What I am trying to present here are patterns of different testing scenarios in a format that should be useful regardless of the testing tools you may be using.
- eagsalazar2 10y agoYou have to learn some tool (react test utils at least) to access and interact with those React components either way. Enzyme is 100% better and more powerful than using the react test utils and way easier to onboard new devs to. All IMO but I def think you should at least check it out.
- analyst74 10y agoIf you use shallow render for your unit tests, Enzyme is much much better than Test Utilities. Just to name a few reasons: - better event simulation - easier to update prop - allow setting and getting state - easier to refresh after triggering changes - comprehensive selector support