Unit Testing in React using Jest and Enzyme
According to Michael Feathers – “Any code that has no tests is a legacy code”. So as a developer it is your duty to avoid creating legacy code by using test-driven development (TDD) . There are many tools available for unit testing in ReactJS but we will be going through Enzyme and Jest . What is Test-Driven Development (TDD)? Test-Driven Development (TDD) is a programming practice which enables developers to write code only if an automated test has failed thereby avoiding duplication of the code. The primary aim of TDD is to write code which is clearer and bug-free. As a developer, you need to write tests for every small functionality of the application. It is a cyclic process and each cycle starts by writing a unit test. Test-Driven Development can easily be compiled in 4 easy steps – 1. Write a test – First, you are going to write a test for every possible challenge. 2. Run the test – Write the minimum code required to pass the test. 3. Re...