初学JavaScript测试框架Mocha,和断言库Chai
在github上的案例
环境配置: vscode
看官方网站介绍
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases. Hosted on Github.
我简单理解一下。Mocha是一个JS测试框架,运行在Node.js和浏览器中,让异步测试变得简单有趣。当映射未捕获的异常到正确的测试案例,考虑到allowing for灵活和精确的报告, Mocha测试连续地serially运行。
看一下放到github上的文档
在文档中想找可以直接使用cdn然后用<script>
在浏览器中运行这种,看一下这个Running Mocha in teh Browser,但是主要用npm来安装mocha包。
首先安装,文档写到
$ npm install mocha
$ mkdir test
$ $EDITOR test/test.js # or open with your favorite editor
这里我是用的是vscode,所以默认这个$EDITOR应该就是“code",我在终端输入code test/test.js
,这个会在这vscode工具中test文件夹里创建一个test.js文件。至于后面这个”#“是什么意思,我也