If your tests aren't working as you expect, you can debug them in both the default Node.js environment and in a real browser.
Debugging in Node.js
Debugging in the default Node.js environment is often the quickest way to diagnose issues that are not related to browser-specific APIs or rendering.
- Run the
ng testcommand with the--debugflag:ng test --debug - The test runner will start in debug mode and wait for a debugger to attach.
- You can now attach your preferred debugger. For example, you can use the built-in Node.js debugger in VS Code or the Chrome DevTools for Node.js.
Debugging in a browser
Debugging in a browser is recommended for tests that rely on the DOM or other browser-specific APIs. This approach allows you to use the browser's own developer tools.
- Ensure you have a browser provider installed. See Running tests in a browser for setup instructions.
- Run the
ng testcommand with both the--browsersand--debugflags:ng test --browsers=chromium --debug - This command runs the tests in a headed browser and keeps it open after the tests finish, allowing you to inspect the output.
- Open the browser's Developer Tools. On Windows, press
Ctrl-Shift-I. On macOS, pressCommand-Option-I. - Go to the Sources tab.
- Use
Control/Command-Pto search for and open your test file. - Set a breakpoint in your test.
- Reload the test runner UI in the browser. The execution will now stop at your breakpoint.