Ad

Coverage In Jest And Enzyme In React Aplication

- 1 answer

I have a React application and I added tests with jest and enzyme. I make a unit test for a react component called <Duration.jsx />. And the coverage shows me all components coverage inside <Duration.jsx /> and files.scss. Is it normal?

Ad

Answer

I think this depends on how you write your tests. IMHO, the coverage is a by-product of tests. For example, if you use enzyme and shallow(<LayoutMessage />), then you are not going to render the children of LayoutMessage.

If you render normally using render(<LayoutMessage />) then you will also render the children of LayoutMessage, increasing the lines that your tests execute.

Here's a sample picture for testing individual component. enter image description here

Ad
source: stackoverflow.com
Ad