soywod / react-pin-field

📟 React component for entering PIN codes.
https://soywod.github.io/react-pin-field/
MIT License
411 stars 23 forks source link

Set up unit tests and coverage #2

Closed soywod closed 4 years ago

bluepioupiou commented 4 years ago

I don't really see the point of unit testing the component... what do you mean by that "unit testing" comparatively to "end2end testing". For me the important point is to see that the component still render correctly and respond to interractions, not to test that some method are sending the good output comparatively to inputs...

soywod commented 4 years ago

Indeed, there is not so much to unit test in this component. However, with this issue, I had in mind to refactor the core with useReducer and to separate the logic from the effects. This way it would be easy to unit test. Maybe I can first refactor, then you do the unit tests?

bluepioupiou commented 4 years ago

I was thinking the same thing : maybe we canevent separate between logic, effects and display and then we'll be able to set some unit tests on logic. But it can be better to create end2end test before so you'll see if you break something during refactor ?

soywod commented 4 years ago

Yes you right, so I'm doing them first and we see after for unit testing.

soywod commented 4 years ago

I will continue the refactor (separate logic / effect), then you will be able to do the unit tests :) I let you know.

bluepioupiou commented 4 years ago

great, looking for it

soywod commented 4 years ago

I finished the refactor: https://github.com/soywod/react-pin-field/compare/6c25d83b64fdc16687a3a9c3cf8ff162a16992c7...d824a46450b939bb23f2332fbd2eacd9f12fb125. All the functions outside of the component can now be tested. I added a comment //TODO: unit tests at the top of them: https://github.com/soywod/react-pin-field/blob/d824a46450b939bb23f2332fbd2eacd9f12fb125/src/pin-field.tsx#L12-L122

soywod commented 4 years ago

Unit tests with Jest and coverage with Codecov set up in the last commit 87efd8fd02be2df908802663b3f5f926dd8d301f. Feel free to add some :)

soywod commented 4 years ago

Add component tests with enzyme in e501a131075eec44d45e6d3fcf6009d960eaeff1.