VSCode调试Angular和Karma测试项目

关于VSCode调试Angular Testing的项目,可以通过以下的步骤。

  • 通过Getting started with Angular创建一个初步的Angular项目
  • 修改src/karma.conf.js
    1
    2
    3
    4
    5
    6
    7
    browsers: ['ChromeDebugging'], //启用Chrome Debugger instance
    customLaunchers:{
    ChromeDebugging:{
    base:'Chrome',
    flags:['--remote-debugging-port=9221']
    }
    },
  • 添加新的配置到launch.json
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    {
    "name": "Debug tests",
    "type": "pwa-chrome",
    "request": "attach",
    "address": "localhost",
    "port": 9221,
    "pathMapping": {
    "/_karma_webpack_/": "${workspaceRoot}/"
    }
    }
  • 在VSCode的Terminal Windows 输入命令ng test, 如果想测试特定的文件可以,使用命令+文件名,如ng test --include '**/project.component.spec.ts'
  • 选择 Debug tests 作为调试选项
  • 在需要调试的地方添加断点
  • 选择需要调试的方法执行

Angular Testing

FAQ

引用

发布