
Unit testing redux containers the better way using jest - rgabs
http://rahulgaba.com/front-end/2018/10/19/unit-testing-redux-containers-the-better-way-using-jest.html
======
jefflombardjr
Maybe I'm missing something here, but I disagree.

>> Since we are exporting a higher order component, it makes testing the
component more complicated than it has to be.

What exactly are you testing on the connected container components? I agree
with the stack overflow article you linked to, just test the components... not
the connected components. [0]

>> While this methods has very less boilerplate code and it allows us to
properly test each function, it kind of a hack since we are exporting a
function just to make is testable which is a code smell. We should export a
part of our code only if it is being used somewhere else, not to test it.

No it's not. Unit tests are good, mocking is the real code smell here.[1] You
should in fact have more of these unit tests instead of a bunch of integration
tests.[2]

Your container components shouldn't be doing much other than what's listed
here.[3]

[0] [https://stackoverflow.com/questions/51943248/react-redux-
tes...](https://stackoverflow.com/questions/51943248/react-redux-testing-
mapstatetoprops-and-mapdispatchtoprops-with-enzyme-jest)

[1] [https://medium.com/javascript-scene/mocking-is-a-code-
smell-...](https://medium.com/javascript-scene/mocking-is-a-code-
smell-944a70c90a6a)

[2] [https://martinfowler.com/articles/practical-test-
pyramid.htm...](https://martinfowler.com/articles/practical-test-pyramid.html)

[3] [https://medium.com/@dan_abramov/smart-and-dumb-
components-7c...](https://medium.com/@dan_abramov/smart-and-dumb-
components-7ca2f9a7c7d0)

