What is testing library ?

If Typescript it’s a superset of Javascript, that takes what javascript does and increases it’s functionality, then Testing Library is exactly the same thing to Jest or other testing frameworks.

Testing Library will run over the most known testing frameworks to the date, increasing their functionality.

47011F60-84F9-4228-9888-D014180153FA.jpeg

Mindset

Using testing library is more similar to end to end testing than unit testing, as it shares the same points of view:

We need to think what the user will expect to see on the screen on each step of the way, so unit testing a component should be checking it’s behavior in relation with the context.

For example, testing a form asking for a username and a password could result in these tests:

As you can see, we don’t test each method inside the component, but the interaction that the user will have with it. If we reach the desired result, that means that the methods inside are working as expected.

Testing library ——> Creates an HTML and adds the element to be tested inside ( creates a controlled environment )

To do the testing correctly we need: