Debugging the Tests
Learn how to debug tests and code when our Jest tests start to fail.
We'll cover the following...
Navigating the failing tests
What do we do when a test fails?
When a test fails, one of two things is happening:
-
Our code is not doing what we think it’s doing.
-
Our test is not testing what we think it’s testing.
As a general rule, fix the code, not the tests. Tests should not be written to pass. They should be written to test our assumptions of how our code works and should pass because our code meets our expectations. If tests fail, the code should be fixed to execute as expected.
However, sometimes tests need to be updated to reflect changes in the codebase. Although, it is best to write tests so that implementation details are not being tested to avoid needing to update them ...