Closed soywod closed 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?
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 ?
Yes you right, so I'm doing them first and we see after for unit testing.
I will continue the refactor (separate logic / effect), then you will be able to do the unit tests :) I let you know.
great, looking for it
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
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...