Idiomatic React Testing Patterns
gist.github.com
Idiomatic React Testing Patterns
1–10 of 28 posts
Re: Idiomatic React Testing Patterns
#2Re: Idiomatic React Testing Patterns
#3See 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
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.
Re: Idiomatic React Testing Patterns
#4See 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
We 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.
Re: Idiomatic React Testing Patterns
#5See 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
We 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.
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.
Re: Idiomatic React Testing Patterns
#6See 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
We 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.
All IMO but I def think you should at least check it out.
Re: Idiomatic React Testing Patterns
#7This means treating the component as an opaque function with inputs (props) and outputs (the rendered result). Your tests just need to that verify that different prop values result in the DOM changes or callbacks that you expect.
Re: Idiomatic React Testing Patterns
#8Earlier quoted context omitted.
We 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.
This 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 testi…
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.
Re: Idiomatic React Testing Patterns
#9 const component = ReactDOM.findDOMNode(TestUtils.renderIntoDocument(
));
we should be writing let node;
const component = TestUtils.renderIntoDocument(
node = n}/>
);
https://gist.github.com/gaearon/7f0e03d3028016bfabfad641720d...Re: Idiomatic React Testing Patterns
#10However, I can see the utility of component testing if I were wrapping something like Ace editor or a jQuery plugin or something of that nature.