joshwcomeau / guppy

🐠A friendly application manager and task runner for React.js
ISC License
3.27k stars 154 forks source link

Component unit tests #309

Open AWolf81 opened 5 years ago

AWolf81 commented 5 years ago

At the moment, we're having no component tests and that makes it difficult to make the coverage diff/patch of codecov pass. We're having pretty good coverage at reducers & sagas but not at the components. That's why the overall coverage was just around 20%. See codecov for the current coverage. codecov

So some things to discuss before this can be started:

We don't need to test every component e.g. the WhimsicalInstaller needs no component tests as it's something that could be easily replaced or disabled with-out affecting the work of the user.

List of components that I think are less important to be tested:

Where I wrote check usage above it would be good to check where and if they're used. I haven't seen them in use but maybe I've missed them.

Describe the solution you'd like After picking the testing utility we can start to work on this.

Some rules to follow - we should add them to the docs later

Tips

AWolf81 commented 5 years ago

I'm working on this. I've picked the ProgressBar component as it's small and is easy to test.

I'll create two branches one with Enzyme and one with react-testing-library. I'll call them component-unit-tests-enzyme and component-unit-tests-testing-lib.

I've started with Enzyme. My WIP is pushed. Progressbar component test with 100% coverage is added. I think I have to tests another component to see how tests with events are working.

I have some questions to my setup:

idoberko2 commented 5 years ago

@AWolf81 are there any decisions regarding the testing library? I can give a hand with writing tests once it's decided.

AWolf81 commented 5 years ago

@idoberko2 no, not decided yet. What do you think? Which direction should we go?

I like the idea of not testing implementation details with testing-lib but I'm not sure and I tend to Enzyme as it's more mature & widely used.

Would be great if you could add an example in a testing-lib branch for another component.

idoberko2 commented 5 years ago

@AWolf81, I knew enzyme from before and only heard about react-testing-library remotely. However, I also find their philosophy interesting and it does seem to be widely used (364K downloads a month, not near as much as enzyme, but substantial). I will give it a try in the component-unit-tests-testing-lib branch and I'll let you know.

AWolf81 commented 5 years ago

@idoberko2 I'm writing a test for the Button component - I'll add it to the todolist above. Once you've started with a test, please let me know and I'll also add it.

idoberko2 commented 5 years ago

@AWolf81 I'm starting off with the Modal component. I'll let you know how it goes.