I'm trying to debug Jest unit tests using VS Code. I have the following config file settings
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules//jest/bin/jest.js",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
However when I run (F5) VS Code I get the following error
Error: AggregatedResult must be present after test run is complete
Any idea why?
VS Code: Debugging Jest 1 Getting started. The VS Code editor has built-in debugging support for the Node.js runtime and can debug any language transpiled into JavaScript. 2 Start debugging. Open the unit test file you want to debug. ... 3 Another way to debug. ... 4 Jest with Chrome debugger. ... 5 CLI Arguments
Read more details about Debugging in VS Code and Node.js debugging in VS Code. Open the unit test file you want to debug. Set breakpoints or the debugger statement where you want to stop. Press Ctrl + Shift + D, or click on the Debug icon in the left panel.
Choose nodejs (jest runs under node). A brand new launch.json file will be displayed. We got a launch.json file under the folder .vscode including a default implementation: In the next step we will replace the content of this file with a new one that will let us integrate the editor with Jest.
In the screenshot, there is a debug configuration active for launching a Chrome instance. To add a new configuration for Jest, hit the cog on the right side of the Launch Chrome selection. It will open a new tab with file launch.json. Or, you can open command palette and search for "Debug: Open launch.json".
About debugging Jest unit tests using VSCode, create a the following file (path: .vscode/launch.json)
If you have created your app using create-react-app
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug tests watch mode",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
"args": ["test", "--runInBand", "--no-cache", "--watchAll=true"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
If you have created your app from scratch:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest watch all tests",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"args": [
"--verbose",
"-i",
"--no-cache",
"--watchAll"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
There are more configurations available, if you need more info check out:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With