Debugger
Debugging allows testers to stop and verify the code at specific breakpoints; this is very important because, in order to make large and complex codes bug-free, we need a proper methodology to tackle with
Setting up Debugger in VS Code.
Click on Run and Debug in the sidebar in VS code, or simply press ctrl + shift + D.

Go to the run configuration and click on add configuration.

A launch.json file will be opened, modify the launch.json file with the following code and save.
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
}
]
}
Now our debugging setup is ready, let’s try debugging some code.
Sample Debugging
In order to debug, we need to add breakpoints in our code where we want our debugger to stop in each test.
Adding Breakpoints
We can add our breakpoints in function as well as test.
Adding breakpoint is very easy in VS code. Hover over the left of the line and click, a red dot will appear, and a breakpoint is added, as shown below.

Running
Simply click the Start debugging button or press F5.

Jest will provide a lot of information like variables, watch, call stack, loaded scripts, breakpoints, to help testers in debugging process.

As shown below, our code should stop at each breakpoint after running the debugger.

Use the below buttons to continue, step over, step into, step out, restart and stop the debugger.

After we go through all breakpoints test will execute and finish.

FAQs
-
What is simulate jest?
simulate() on the actual node that has the event handler set. simulate() will target the component's prop based on the event you give it.
-
Does Jest have cache?
The default cache directory can be found by calling jest --showConfig . Note: clearing the cache will reduce performance.
-
How do I speed up Jest test?
When you have Jest as your test runner, passing the --maxWorkers=50% option will make the tests faster in most cases. For watch mode, use --maxWorkers=25%, and for CI disable Jest workers with --runInBand.
-
Do Jest tests run sequentially?
Once the described blocks are complete, by default, Jest runs all the tests serially in the order they were encountered in the collection phase, waiting for each to finish and be tidied up before moving on.
Key Takeaways
For a failed test case, Jest specifies in which line test fails. It also shows the received value and value is expected. For detailed debugging, we can set up a debugger in VS Code; we have seen the step-by-step process to set up a debugger, information like variables, call stack, breakpoints, etc., provided by debugger help testers to test and debug any complex code quickly.
Learning never stops, and to feed your quest to learn and become more skilled, head over to our practice platform Coding Ninjas Studio to practice top problems, attempt mock tests, read interview experiences, and much more.!
Happy Learning!