Search posts, tags, users, and pages
How do you test your React components? And how is Redux working out for you?
Testing React components is tough, you've so many way to test them :) We've written a blog post about it here: blog.algolia.com/how-we-unit-test-react-component…
Redux is working great so far. Separating data logic from the views/component is liberating. It is also really easy to test the actions and reducers because they are just pure functions. We are still trying to find ways to decrease the boilerplate though (we have something in the works for this :).
Re testing components: on the website, we use a combination of airbnb’s enzyme and our very own vvo’s expect-jsx
We started testing React components with expect-jsx: https://github.com/algolia/expect-jsx that we built. But then testing for events is a bit tricky, we explain it on our blog blog.algolia.com/how-we-unit-test-react-component….
Right now the airbnb project called enzyme http://airbnb.io/enzyme/ seems to be the most promising testing library.
I also believe the React team is working hard to make all this easier. Right now it's a bit tricky to know how to test React.
We are currently unit testing our reducers by using mocha, chai.js and sinon.js while we're using expect-jsx for integration / functional tests.
So far Redux has proven to be very helpful in helping us handle state updates without undesired side effects: we managed to remove most of the local state from our UI components. The only downside we found is a little bit too much boilerplate code, especially when handling asynchronous flows. It’s definitely working well for us, we 💖React and Redux!