在 VS Code 中调试 jest 测试显示“错误:找不到模块“jest-environment-node”

Luk*_*ger 4 node.js jestjs visual-studio-code

我在调试笑话测试时遇到了麻烦。也许我先介绍一下我的设置:

root-dir
  test
    sample.spec.ts
  jest.config.js
  package.json
  tsconfig.json
Run Code Online (Sandbox Code Playgroud)

内容sample.spec.ts

describe('Sample', () => {
  it.concurrent('App', async () => {
    expect(true).toEqual(true); // here the breakpoint is set
});
Run Code Online (Sandbox Code Playgroud)

});

所以这里没有什么需要调试的。我在 VS Code 中安装了Jest Runner扩展。

但是,当我“单击”正上方的“调试”按钮时it,调试器启动,但显示异常:

Exception has occurred: Error: Cannot find module 'jest-environment-<path-to-my-root-dir>\node_modules\jest-environment-node\build\index.js/package.json' from '<path-to-my-root-dir>'e
Run Code Online (Sandbox Code Playgroud)

那里有什么问题呢?在node_modules目录中,jest-environment-node有 。异常的路径不正确,因此找不到package.json. 但这件事我无法影响!

我感谢您的帮助!

向大家致以亲切的问候!

Luk*_*ger 6

我已经找到了这个问题的解决方案......这根本不是问题。这里也回答了:找不到模块 jest-sequencer-@jest/test-sequencer

所以...永远不要在 VS Code 中勾选Caught Exceptions和:Uncaught Exceptions例外情况

没有这两个勾,jest开箱即用。