小编aus*_*eow的帖子

Babel + Mocha 堆栈跟踪报告错误的行号

使用 Babel 6 和 Mocha 时,堆栈跟踪报告错误的行号。我很确定这是因为转译添加了额外的代码。对我来说,这是 Babel 6 与 Babel 5.x 中的新行为。有人有关于如何在使用 Mocha 进行单元测试时解决此问题的解决方案吗?

这是我的 .babelrc 配置:

{
  "ignore": [
    "node_modules",
    "bower_components"
  ],
  "presets": [
    "es2015",
    "react"
  ],
  "plugins": [
    "transform-react-constant-elements",
    "syntax-async-functions",
    "transform-regenerator"
  ]
}
Run Code Online (Sandbox Code Playgroud)

注意:无论我是否在应用程序的入口点 require('babel-polyfill') ,都会发生这种情况。

示例堆栈跟踪如下所示:

TypeError: Cannot read property 'should' of undefined
    at _callee2$ (test/unit/index.test.js:217:34)
    at step (test/unit/index.test.js:27:284)
Run Code Online (Sandbox Code Playgroud)

mocha.js node.js babeljs

3
推荐指数
1
解决办法
1517
查看次数

标签 统计

babeljs ×1

mocha.js ×1

node.js ×1