Why Do We Test?

We write tests to ensure that the code that we wrote does what we expect it to do. Code is constantly changing, and to ensure that the assumptions that were valid when we wrote the code are still true today we need tests to check our code. Tests make our code more reliable, they ensure that working code keeps working which ultimately allows us to move faster.

Types of Testing

Untitled

E2E Tests

Snapshot Testing

Snapshot tests test the rendering of a component with a given set of inputs, due to the functional composition style of react components this tests almost always test other components. Because of the long dependency chain snapshot tests should give us signal about what's changing across our code. We should look at the differences between the snapshot and what was updated, but we don't need to be scared of updating our snapshots. The changes in the snapshot give us a history of how the component changed over time which can be useful when investigating code changes for debugging.

Code Examples of E2E Tests

Integration Tests

Unit Tests

A note on test coverage

Running all tests in the https://github.com/invisible-tech/invisible repository

nx affected:test or nx run-many --all --target=test

This should create a coverage report in the coverage directory in the root directory of the invisible repo.