Open AWolf81 opened 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:
*.stories.js
as we don't need to write test for stories, right? How are the docz
files called later?index.js
file inside of every component? Should we test it or is it OK to add it to the coverage ignore list? I think it's OK to ignore as we're following the style with the export default.@AWolf81 are there any decisions regarding the testing library? I can give a hand with writing tests once it's decided.
@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.
@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.
@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.
@AWolf81 I'm starting off with the Modal
component. I'll let you know how it goes.
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](https://codecov.io/gh/joshwcomeau/guppy/branch/master/graph/badge.svg)
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
shallow
overmount
- use mount only if it includes Redux & you need the store or you're testing styled-components. Example of a connected component test (seeProjectPage.test
)simulate
instead of usinginstance.clickHandler
- so we're also testing that the handler is called correctly.Tips
console.log(wrapper.debug())
can help debugging or use the built-in debugger in VS codeconst instance = wrapper.instance()
can be used to test instance methods or life-cycle hooks.