How to configure debugger when running jest for React unit tests with VS Code
- By : Mydatahack
- Category : Front-End, Web Technologies
- Tags: Jest, React, VS Code
We can debug the jest test with console.log (make sure to remove the -silent option). But, attaching a debugger and stepping through the tests sometimes may help us to troubleshoot quicker under certain circumstances.
1. Install Jest Plugin
Install Jest plugin.
2. Configure
Press cmd + shift + p.
Find Jest: Setup Extension (Beta)
Add yarn test (or any test command you usually use for running tests) as Setup Jest Command.
Add launch.json with Setup Jest Debug Config. By using the wizard, it will automatically generate launch.json according to the yarn test command.
3. Run
Add breakpoint and run individual test from the test file. You can see Debug above the test scenario and click it. See the plugin doc for further info.