You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The –require option is useful for libraries such as should.js, so you may simply –require should instead of manually invoking require(‘should’) within each test file.
Only interested in the first exception? use –bail!
--bail可以在第一个异常抛出的时候停止运行测试,这对集成测试很重要。
About Babel
If your ES6 modules have extension .js, you can npm install –save-dev babel-register and use mocha –require babel-register; –compilers is only necessary if you need to specify a file extension.
2020-07-08 18:23:34
因为 Mocha 默认支持 commonJS
参考资料 https://greenfavo.github.io/blog/docs/02.html
如果直接引入 import 会报错, 这让 写 es 语法的时候无法通过 import 来直接测试
这里借助 babel 转换
定义 scripts 运行 test Mocha 会自动执行 test 目录的测试代码
为了支持es6语法,加上以下代码
安装依赖
新建 .babelrc
babel会自动读取
.babelrc
配置文件,这样就让我们的Mocha代码支持es6的模块系统和es6的其他语法了运行
npm run test
Mocha配置说明 (纯复制
The text was updated successfully, but these errors were encountered: