jeudi 27 juin 2019

Is exporting a function just for testing considered a bad practice?

I have this question especially after reading the official redux documentation on testing React components:

https://github.com/reduxjs/redux/blob/master/docs/recipes/WritingTests.md

In order to be able to test the App component itself without having to deal with the decorator, we recommend you to also export the undecorated component

Even the famous https://www.reactboilerplate.com/ exports named unconnected components just to be able to test them without mocking a store.

But isn't it considered bad to export something just so it makes things easier to test?

There might be cases when a developer makes the wrong import and introduces a bug just because there are two things exported from a file.

So, the question essentially is:

Can we make changes to the actual code to make testing easier?

Although this question is specific to React, would be great to know if any other languages or frameworks have similar problems and how they are dealt with.

Aucun commentaire:

Enregistrer un commentaire