首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用create-react-app调试jest单元测试不会命中VSCode中的断点

使用create-react-app调试jest单元测试不会命中VSCode中的断点
EN

Stack Overflow用户
提问于 2018-11-28 02:29:28
回答 1查看 851关注 0票数 2

我正在尝试调试使用create-react-app/jest/enzyme创建的测试,但在VScode中无法命中断点。当我运行debug "Debug CRA Tests“时,所有的工作和测试都通过了,但它没有命中VSCode中的断点。

我的配置/设置中是否遗漏了什么?

代码语言:javascript
复制
import React from "react";
import { configure, shallow } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import Input from "./Input";

configure({ adapter: new Adapter() });

describe("<Input />", () => {

    it("should render <Input label=.../> with label", () => {
        const wrapper = shallow(<Input elementType="input" />);
        wrapper.setProps({ label: "test" });
        expect(wrapper.find("label")).toHaveLength(1);
    });

});

这就是我的launch.json:

代码语言:javascript
复制
   {
        "name": "Debug CRA Tests",
        "type": "node",
        "request": "launch",
        "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
        "args": [
            "test",
            "--runInBand",
            "--no-cache"
        ],
        "cwd": "${workspaceRoot}",
        "protocol": "inspector",
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen"
    }

和我的package.json:

代码语言:javascript
复制
"dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.6",
    "@fortawesome/free-solid-svg-icons": "^5.4.1",
    "@fortawesome/react-fontawesome": "^0.1.3",
    "axios": "^0.18.0",
    "moment": "^2.22.2",
    "react": "^16.6.0",
    "react-dom": "^16.6.0",
    "react-redux": "^5.0.7",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.0.5",
    "react-swipeable": "^4.3.0",
    "redux": "^4.0.1",
    "redux-saga": "^0.16.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "enzyme": "^3.7.0",
    "enzyme-adapter-react-16": "^1.6.0",
    "node-sass": "^4.9.4"
  }

....
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-13 06:25:00

在使用create-react-apps文档中指出的vscode启动配置时,我也遇到了类似的问题。

它不起作用是因为--no-watch参数不起作用。The solution:使用另一种他们必须不使用监视模式的方式:

代码语言:javascript
复制
"env": {
    "CI": "true"
}

完整的配置工作(Node v8.12.0,react-scripts v2.1.3,Jest 23.6.0)

代码语言:javascript
复制
 {
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug CRA Tests",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
      "args": ["test", "--runInBand", "--no-cache", "--no-watch"],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "env": {
        "CI": "true"
      }
    }
  ]
}

这就是在撰写本文时他们的文档中所述的

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53505993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档