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 ...
随机推荐
- linux下关于mysql的命令的用法
所有关于mysql的命令都在/usr/bin/中, 使用 /usr/bin | grep 'mysql'可以列出这些mysql命令 导出数据库, 可以直接在 命令行中, 使用 mysqldump -u ...
- SpringBoot Mybatis 分页插件PageHelper
添加maven配置: <!-- 分布插件 --> <dependency> <groupId>com.github.pagehelper</groupId&g ...
- Linux command: grep
How to use grep to match multiple strings in the same line? grep 'string1\|string2' filename grep -E ...
- P2257 YY的GCD(莫比乌斯反演)
第一次做莫比乌斯反演,推式子真是快乐的很啊(棒读) 前置 若函数\(F(n)\)和\(f(d)\)存在以下关系 \[ F(n)=\sum_{n|d}f(d) \] 则可以推出 \[ f(n)=\sum ...
- Unity3D学习笔记(二十七):MVC框架下的背包系统(2)
Tools FileTools using System.Collections; using System.Collections.Generic; using UnityEngine; using ...
- HDU 5727 Necklace(全排列+二分图匹配)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5727 题意:现在有n个阳珠子和n个阴珠子,现在要把它们串成项链,要求是阴阳珠子间隔串,但是有些阴阳珠 ...
- python学习 day07打卡 文件操作
本节主要内容: 初识文件操作 只读(r,rb) 只读(w,wb) 追加(a,ab) r+读写 w+写读 a+追加写读 其他操作方法 文件的修改以及另一种打开文件句柄的方法 一. 初识文件操作 使用py ...
- Jenkins参数化构建(三)之 Jenkins从文件中读取运行参数
安装Extended Choice Parameter插件 选择‘参数化构建过程’ maven command line中进行引用 clean test -DsuiteXmlFile=src/main ...
- 查看iis对应w3wp.exe显示的进程ID号
1.任务管理器,查看,选择列,选择PID(进程标识符) 2.通过cmd查询: 管理员身份运行cmd,跳转到C:\Windows\System32\inetsrv目录,然后运行appcmd list w ...
- Perl中命令行参数以及打开管道文件
打开管道文件 Linux提供了管道机制,可以方便应用程序之间的数据传递.在Perl中,扣开和使用管道可采用如下形式的open函数: open(Filehandle,”丨 CMD”); 其中 ...
- Practical Node.js (2018版) 第7章:Boosting Node.js and Mongoose