【vue】在VS Code中調試Jest單元測試

在VS Code中調試Jest單元測試

添加調試任務

  • 打開 vscode launch.json 文件,在 configurations 內加入下面代碼
"configurations": [
    {
        "name": "Jest Debug AllFile",
        "type": "node",
        "request": "launch",
        "protocol": "inspector",
        "program": "${workspaceRoot}/node_modules/jest/bin/jest",
        "stopOnEntry": false,
        "args": ["--runInBand", "--env=jsdom"],
        "runtimeArgs": [
            "--inspect-brk"
        ],
        "cwd": "${workspaceRoot}",
        "sourceMaps": true,
        "console": "integratedTerminal"
    },
    {
        "name": "Jest Debug File",
        "type": "node",
        "request": "launch",
        "protocol": "inspector",
        "program": "${workspaceRoot}/node_modules/jest/bin/jest",
        "stopOnEntry": false,
        "args": ["--runInBand", "--env=jsdom", "${fileBasename}"],
        "runtimeArgs": [
            "--inspect-brk"
        ],
        "cwd": "${workspaceRoot}",
        "sourceMaps": true,
        "console": "integratedTerminal"
    },
 ]

設置斷點開始調試

  • 打開 vscode 的斷點調試工具node

  • 對單文件調試
    在對應的測試文件下,執行 Jest Debug Filejson

  • 對全部文件調試
    在任意位置執行,執行 Jest Debug AllFile

    dom

  • 斷點調試

    在調試控制檯,能夠查看測試代碼,以及提示

    在VS Code中調試Jest單元測試工具

相關文章
相關標籤/搜索