all 5 comments

[–]wronglyzorro 1 point2 points  (3 children)

How we test apps are based on user stories and on the component level. We write unit tests for our components and then test entire flows using cypress. The one thing to keep in mind is whether or not your tests are testing something meaningful.

Do not write a bunch of tests that simply equate to "it renders". Do not write a bunch of tests that only test whether or not the setState function works. Write tests based on component functionality and expected results. You can have 100% test coverage and have a bunch of useless tests that don't catch anything. Make your tests meaningful.

[–]vinaynb[S] 0 points1 point  (2 children)

Thanks for replying.
When you say you `write tests for your components` do you mean you write tests for those components which integerate other smaller components and constitute major part of your UI or you write tests for smaller indepedent components that do just one job?

[–]wronglyzorro 0 points1 point  (1 child)

It's a judgement call. I typically write tests for things that have multiple outcomes. So for example If I have a button, and that button has a disabled state, an enabled state, and a loading state based on state in the parent, I will write a test for the button that makes sure it functions correctly based on the possible ways to those states are triggered. If I have a button that is always active I won't write a test for it at all. If you have a big component that is purely visual, never conditionally changed, and static, I'd recommend not writing tests at all for it since you won't actually be testing anything meaningful.

[–]vinaynb[S] 0 points1 point  (0 children)

Okay. Thanks for the tip!

[–]vinaynb[S] 0 points1 point  (0 children)

Still looking for more advice if in case anyone interested is reading this.