简体   繁体   English

VS Code 断点跳转到其他行

[英]VS Code breakpoints jump to other lines

As I haven't solved my other issue yet Randomly failing tests jest and supertest Node.js I've decided to use the VS Code debugger.由于我还没有解决我的另一个问题随机失败的测试 jest 和 supertest Node.js我决定使用VS Code调试器。 I thought that it would be pretty simple but after I've set a breakpoint at the certain line and run the debugger I find my breakpoint icon in a different place and my code stops there.我认为这会很简单,但是在特定行设置断点并运行调试器后,我发现断点图标位于不同的位置,我的代码停在那里。

My launch.json file:我的launch.json文件:

{
    "type": "node",
    "request": "launch",
    "name": "Jest Current File",
    "program": "${workspaceFolder}/node_modules/jest/bin/jest",
    "args": ["${relativeFile}"]
}

Before:之前: 在此处输入图片说明

After:之后: 在此处输入图片说明

Any idea why this happens?知道为什么会这样吗?

I'm just using plain mocha, so might be a bit different.我只是使用普通的摩卡咖啡,所以可能有点不同。 But I've noticed this before, and I would set an inline break point (cmd+shift+p - search inline breakpoint) inside the then()但我之前已经注意到了这一点,我会在 then() 中设置一个内联断点(cmd+shift+p - 搜索内联断点)

Use .catch() after .then() , according to my experience, it isn't going to .then() due to some exception called and the catch is not invoked.使用.catch()之后.then()根据我的经验,它是不会.then()由于一些例外打来电话,美中不足的是不被调用。 I have worked on testing using chai mocha, had the same issue.我一直在使用 chai mocha 进行测试,遇到了同样的问题。 Try to add .catch() it will show that your API might be faulty and reaching a catch statement.尝试添加.catch()它将表明您的 API 可能有问题并到达 catch 语句。

您可以尝试清理您的工作区并创建一个新的launch.json文件

I had same problem, I've updated my VScode and change my Lunch file like this:我遇到了同样的问题,我已经updated我的 VScode 并像这样更改了我的午餐文件:

{
    "type": "node",
    "request": "launch",
    "name": "Jest tests",
    "program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
    "args": ["--verbose", "-i", "--no-cache"],
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
}

Generally in some IDEs, the breakpoints are fixed to the line number.一般在一些IDE中,断点是固定在行号上的。 So if code in that file changes after the breakpoint is set, the breakpoint doesn't move.因此,如果设置断点后该文件中的代码发生更改,则断点不会移动。 So when making changes,所以在修改的时候,

  • stop the debug mode停止调试模式
  • make the changes做出改变
  • set the breakpoint设置断点
  • start debug mode again.再次启动调试模式。 This worked for me.这对我有用。

Execution is not going to that line due to some error thrown by the API request.由于 API 请求引发了一些错误,因此不会执行到该行。 Handle the error using catch block.使用 catch 块处理错误。 Print the error in catch block.在 catch 块中打印错误。 You can also add the break point for the code in catch block to check more details about the error.您还可以在 catch 块中为代码添加断点以检查有关错误的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM