I have many jest tests, within many test suites, within many test files.
I need to isolate and debug a single test.
I'm debugging via node --inspect-brk ./node_modules/jest/bin/jest
, so other solutions involving watch mode are too complicated.
How can I skip all tests except the one I need to debug?
jest handles this in two steps
isolate your test file by running jest with the testPathPattern (jest docs) command line argument
node --inspect-brk ./node_modules/jest/bin/jest --testPathPattern="integration.test"
here integration.test
is supplied as a regular expression to filter for the correct test file
isolate your test function
there are two ways to do this
one way is to use the testNamePattern (jest docs) command line argument
node --inspect-brk ./node_modules/jest/bin/jest --testNamePattern="host events"
here host events
is supplied as a regular expression to filter for the correct test suite name
alternatively, you can add .only
to your test function:
so that test("object works", async() => {/*...*/})
becomes test.only("object works", async() => {/*...*/})
I am using VSCode for debugging and in launch.json add to runTimeArgs a testPathPattern as your folder name:
{
"version": "0.2.0",
"configurations": [{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--runInBand",
"--testPathPattern=<NameOfTheFolder-you-want-to-test-without-this-angle-brackets>"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
}]
}
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