Hi everyone,
In this article, I'll show you how we can make tests using two awesome tools: chai and mocha.
But first of all, I'd like to tell about the importance of testing. Why tests are so necessary? For this, I should explain what TDD is.
The Test-Driven Development (TDD) is a software engineering process that requires unit tests to be written before the code they are supposed to validate that relies on the repetition of a very short development cycle, where the requirements are transformed in test cases. With this, firstly the code will fail (miserably), then the developer should write clean code that works to make the tests pass.
The cycle is very simple. The developer writes a test, this test will fail because you haven't developed any code for these tests, so the developer should check if the tests are failing. After this, the developer writes clean code to make the tests pass. Again, the developer should check if all tests are passing, if not, it should go back to write code. And, finally, we should remember to make our code always better and refactor it to create new tests.