【问题标题】:Jest: why does it fail with TypeError: Path must be a string. Received undefined开玩笑:为什么它会因 TypeError 失败:路径必须是字符串。收到未定义
【发布时间】:2018-10-13 03:06:16
【问题描述】:

我编写了一个 React 应用程序并使用 jest 编写单元测试。

当我通过“jest --config=jest.config.json --watch”运行它时,我收到以下错误:

● 测试套件无法运行

TypeError: Path must be a string. Received undefined

  at assertPath (path.js:7:11)
  at Object.relative (path.js:1226:5)

我的 jest.config.json 是:

{
    "snapshotSerializers": [
        "enzyme-to-json/serializer"
    ],
    "transformIgnorePatterns": [
        "node_modules/(?!(react-native|my-project|redux-persist)/)"
    ]
}

【问题讨论】:

    标签: reactjs jestjs


    【解决方案1】:

    由于我使用 create-react-app 构建了我的应用程序,因此我只运行了“npm test”并且测试运行成功。

    我知道 Jest 会自动包含在项目中,并且 可能手动添加 jest 到 package.json 是无效的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-23
      • 2019-06-04
      • 1970-01-01
      • 2016-04-29
      • 2016-10-13
      • 2021-09-08
      • 2020-12-30
      • 1970-01-01
      相关资源
      最近更新 更多