Mocha安装常见问题及解决方案

问题一:运行验证脚本test.js,返回“module.js:549 throw err; Error:Connot find module ''chai”

解决方法:在dos窗口下先运行npm install -g mocha;然后执行命令npm install --save-dev chai;最后再次运行验证脚本即可。

问题二:window下安装npm,在以下命令“git clone --recursive git://github.com/isaacs/npm.git”后,执行以下命令cd npm,然后执行node cli.js install npm -gf,出现错误:mode.js:549 throw err; Error:Cannot find module ''npm-6.2.0-next.1\bin\cli.js"

解决方法:对npm文件夹进行全局搜索,查找cli.js所在的目录(如在F:\npm-6.2.0-next.1\bin\cli.js),然后把完整目录复制出来替换指令里面的cli.js,即重新执行node F:\npm-6.2.0-next.1\bin\cli.js install npm -gf即可。

问题三:当使用WebStorm集成Mocha+Chai进行js单元测试时,如果配置好webstorm的调试属性(Run/Debug Configurations)后运行,出现以下错误“Find no module "chai”",而实际在本机上已安装“chai”模块

解决方法:上述问题可能是“Run/Debug Configurations”中配置的“Test directory”测试目录不在Mocha安装目录下(chai模块安装在该目录下-安装该模块时可自行选择),不能找到chai模块引起的。所以最直接的解决方法就是将webstorm下创建的测试工程直接放置在mocha安装目录下。

猜你喜欢

转载自blog.csdn.net/qq_30068487/article/details/81454520