Practical Node.js (2018版) 第3章:测试/Mocha.js, Chai.js, Expect.js
TDD and BDD for Node.js with Mocha
TDD测试驱动开发。自动测试代码。
BDD: behavior-driven development行为驱动开发,基于TDD。一种自然化的测试语言。
例如,使用expect(response.status).to.equal(200)代替了TDD的assert.equal(response.status, 200)
Mocha文档:https://mochajs.org/
chai: 官网文档: https://www.chaijs.com/
Node.js文档: https://nodejs.org/api/async_hooks.html
Mocha阮一峰的测试框架 Mocha 实例教程
Chai断言库可以看Chai.js断言库API中文文档
Mocha 摩卡☕️
(点击连接看git)(方法:文档)
本章介绍:比较流行的javascript test framework for Node.js和browser: mocha
涉及以下方面:
- 安装理解Mocha
- TDD的assert。
- BDD的expect.js模块。
- Project: 为上个章节的Blog app写一个测试。
Installing and Understanding Mocha(17000✨)
Mocha是成熟的强大的测试框架。全局安装
$ npm install –-global mocha
驱动测试开发基本步骤:
- 写测试
- 写让测试通过的代码
- 确认测试通过,并重复1,2步骤。
BDD是TDD的特色版本。它使用单元测试,逐步满足商业需求。
Node.js核心模块是assert。但是,使用明确的testing library更好。
本章使用Mocha测试框架,让许多事情变得更"free",因为Mocha可以:
- Reporting
- 异步支持
- 丰富的可配置性
- 通知Notifications
- Debugger 支持
- 常用的交互:before, after钩子
- 文件watcher支持。
使用Mocha有更多的功能和好处。这里有一个选项参数名单,使用$ mocha [options]命令。
全的list:mocha -h
例如:
mocha test-expect.js -R nyan

选择一个框架的类型,有很多选择。Mocha是作者推荐的一个,有17k✨。除此之外还有以下选择:
- Jest (https://facebook.github.io/jest):(2k✨) A framework for mostly React and browser testing, which is built on Jasmine and has a lot of things included
- Jasmine: (https://jasmine.github.io):(1.4k✨) A BDD framework for Node and browser testing, which follows Mocha notation
- Vows (http://vowsjs.org): (1.6k✨)A BDD framework for asynchronous testing
- Enzyme (1.6k
Practical Node.js (2018版) 第3章:测试/Mocha.js, Chai.js, Expect.js的更多相关文章
- Practical Node.js (2018版) 第7章:Boosting Node.js and Mongoose
参考:博客 https://www.cnblogs.com/chentianwei/p/10268346.html 参考: mongoose官网(https://mongoosejs.com/docs ...
- Practical Node.js (2018版) 第5章:数据库 使用MongoDB和Mongoose,或者node.js的native驱动。
Persistence with MongoDB and Mongoose https://github.com/azat-co/practicalnode/blob/master/chapter5/ ...
- Practical Node.js (2018版) 第10章:Getting Node.js Apps Production Ready
Getting Node.js Apps Production Ready 部署程序需要知道的方面: Environment variables Express.js in production So ...
- Practical Node.js (2018版) 第9章: 使用WebSocket建立实时程序,原生的WebSocket使用介绍,Socket.IO的基本使用介绍。
Real-Time Apps with WebSocket, Socket.IO, and DerbyJS 实时程序的使用变得越来越广泛,如传统的交易,游戏,社交,开发工具DevOps tools, ...
- Practical Node.js (2018版) 第8章:Building Node.js REST API Servers
Building Node.js REST API Servers with Express.js and Hapi Modern-day web developers use an architec ...
- Practical Node.js (2018版) 第4章: 模版引擎
Template Engines: Pug and Handlebars 一个模版引擎是一个库或框架.它用一些rules/languages来解释data和渲染views. web app中,view ...
- Practical Node.js (2018版) 13章, Node HTTP/2 Servers
新增的章节. If you are not using HTTP/2, then you are losing out on big improvements. HTTP/2相比http/1有很大的区 ...
- Practical Node.js (2018版) 14章, async code in Node
Asynchronous Code in Node 历史上,Node开发者只能用回调和事件emitters. 现在可以使用一些异步的语法: async module Promises Async/aw ...
- Node入门教程(13)第十一章:mocha单元测试+should断言库+istanbul覆盖率测试+art-template
声明:以下为老马的全栈视频教程的笔记,如果需要了解详情,请直接配合视频学习.视频全部免费,视频地址:https://ke.qq.com/course/294595?tuin=1eb4a0a4 node ...
随机推荐
- topcoder srm 535 div1
problem1 link 对于每个质因子$p$,枚举其出现的最少次数以及最多次数分别在哪个数字中. problem2 link 分数规划.题目是求$\frac{3600K+\sum_{i=0}^{K ...
- Vue学习【第二篇】:ES6简单介绍
ECMAScript 6简介 ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准,已经在 2015 年 6 月正式发布了.它的目标,是使得 JavaScript ...
- P3317 [SDOI2014]重建
思路 变元矩阵树定理可以统计最小生成树边权积的和,将A矩阵变为边权,D变为与该点相连的边权和,K=D-A,求K的行列式即可 把式子化成 \[ \begin{align}&\sum_{T}\pr ...
- MySQL的启动和关闭
1.Windows下 启动服务 mysqld --console 或 net start mysql 关闭服务 mysqladmin -uroot shudown 或 net stop mysql 2 ...
- 【Hadoop 分布式部署 十 一: NameNode HA 自动故障转移】
问题描述: 上一篇就是NameNode 的HA 部署完成,但是存在问题,问题是如果 主NameNode的节点宕机了,还是需要人工去使用命令来切换NameNode的Acitve 这样很不方便,所以 ...
- Footnotes for tables in latex - 为latex的table加上footnotes
参考: Footnotes for tables in LaTeX Footnote in tabular environment Footnotes for tables in latex - 为l ...
- sprinf sprintf_s 的用法
函数功能: 将数据格式化输出到字符串 函数原型: int sprintf( char *buffer, const char *format [,argument] ... ) 注意这里的buffer ...
- 【Oracle】【问题】
1. java.sql.SQLException: 对只转发结果集的无效操作: last 参考:https://www.cnblogs.com/gaoyuchuanIT/articles/411888 ...
- spring boot配置druid数据源和监控配置
直接上代码: 一.pom.xml中添加依赖 <dependency> <groupId>com.github.drtrang</groupId> <artif ...
- 堆+建堆、插入、删除、排序+java实现
package testpackage; import java.util.Arrays; public class Heap { //建立大顶堆 public static void buildMa ...
- Practical Node.js (2018版) 第7章:Boosting Node.js and Mongoose