Debugging the Tests
Explore methods to debug failing tests in Jest by using the debugger statement and integrating debugging tools like Chrome DevTools and VSCode. Understand how to inspect test variables, set breakpoints, and correct code issues ensuring your tests reflect true code behavior.
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 ...