When to do unit tests in JavaScript?

3

As far as it is advantageous to do unit tests on the presentation layer, what are the scenarios where Javascript unit testing is advantageous?

Is it only advantageous if you have calculations in Javascript?

Obs : I'll use Jasmine for testing.

    
asked by anonymous 07.12.2017 / 12:50

1 answer

1

Starting from Software Engineering (more summarized). Unit tests are derived from test cases, which in turn are based on use cases. You would need to have documentation for your system with:

  • Requirements List or basic guidelines for your system. Nothing to include animations, interfaces . They should only treat description of functionalities, being as simple as possible and not generic. Ex: The system should allow the user to change their credentials.

  • For each requirement, mount one or more Usage Cases , citing in detail how the user will use the system to perform the Requirement.

So for each use case , you create more than one test case , with inputs, outputs expected, and outputs obtained. Note that it is not possible to create a test case for interface because the interface is not a System Requirement.

This is because the interface is a surface layer of the system it totally depends on something that needs to be tested, so it is no longer a true unit test. In addition, its interface could transmit wrong entries to the next levels of the system, making it difficult to identify the outputs.

There are cases where you do not have the system and become a fully front-end application, but even then it would be difficult and costly to find out all possible test cases. I'm not saying that it is not possible to test GUI, but that it would not be feasible, nor does it guarantee the best maintainability of the system, since the test cases would be superficial.

    
25.03.2018 / 06:06