- Using
create-react-app
, what do we need to set up for testing? - What components are worth to test in your development?
- Can you apply TDD once you already created components?
NOTE: Apply TDD as much as you can.
- Find any sub-routine, extract that logic into a separate file and test it out.
- Run test coverage and save results into a .txt file at ./ - root level. Can you make the total coverage to be above of 60%?
- Meaningful test cases were implemented for components and sub-routines logic.
- All the test cases were successful.
- Test coverage is above 60%.
Answers to questions
Using create-react-app, what do we need to set up for testing?
Nothing, creating a React app by using
npx create-react-app app
this creates a new application with all the necessary stuff to test our application, to run a development server, and to build a minimized bundle for production.What components are worth to test in your development?
Well, summed in few words, components with high-value features
Within these, from my experience, I think we can consider the following:
Maybe there are a few more, but I think this answers the question.
Can you apply TDD once you already created components?
Yes, here's why:
TDD is only an approach for software development, if you haven't been applying TDD but you have been creating tests for your components, that's just a different approach and by using a different approach it just means different advantages, disadvantages and tradeoffs compared to TDD.
I love to use TDD. Since I leared how to test my applications and why is this so important, I changed the focus of Build first, test later to Test first, build later because I noted that helped me build better apps, why? the next are the following reasons for me:
So, after all, you can TDD your app's components once they're created.
Maybe even you can realize things as me, for example, that I was able to get rid of some unnecesary code that was just making my code cumbersome.
EDITED: Well, I wrote this time ago, but according to the readings, it is not possible, because it is a process you must start from the beginning... I'm not very sure about this, but I argue that it is possible, because once you start writing a test, it is a new beginning, so, I say yes, authors say no... I don't know what to believe.