Debug Node.js Unit Tests

Learn techniques that enable and facilitate debugging.

Debugging our unit tests is very important. There are a few techniques for doing that.

Run a single test

Isolating a single test allows us to focus on it and make sure the issue we are debugging is indeed caused by this test. Jasmine provides the fit capability for focusing on a single test and only running it, skipping all the rest.

fit('this is the only test that will run', () => {...})

It works for multiple instances of fit too. See the example below.

fit('this is the only test that will run', () => {...})
fit('this is the only other test that will run', () => {...})

Using the console.log

The console.log (and its sibling methods info, table, …) allows us to log out states and markers at various stages of the execution of our tests. Let’s see an example in the playground below.

Get hands-on with 1400+ tech skills courses.