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 ...
随机推荐
- 【python017--函数对象1】
一.函数 1.定义函数:def 函数名(): 2.调用函数:直接写函数的名称() >>> def MyFirstFunction(): print('this my firs ...
- Python3 tkinter基础 Canvas create_rectangle 画虚边的矩形 create_oval 画椭圆形 圆形
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 list count 查询指定元素在列表中出现了多少次
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 【第四十章】Spring Boot 自定义拦截器
1.首先编写拦截器代码 package com.sarnath.interceptor; import javax.servlet.http.HttpServletRequest; import ja ...
- 【Dalston】【第二章】客户端负载均衡(Ribbon)
对于大型应用系统负载均衡(LB:Load Balancing)是首要被解决一个问题.在微服务之前LB方案主要是集中式负载均衡方案,在服务消费者和服务提供者之间又一个独立的LB,LB通常是专门的硬件,如 ...
- iframe初始化属性
<iframe id="user" src="xxx.html" frameborder="0" width="" ...
- Python 安装与环境变量配置
一.软件下载 Python安装包下载地址:https://www.python.org/ 二.安装过程(略) 三.环境变量配置: 方法一:使用cmd命令添加path环境变量 在cmd下输入: path ...
- Leetcode167-Two Sum II Input array is sorted-Easy
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
- 20165306学习基础和C语言基础调查
20165306学习基础和C语言基础调查 技能学习心得 我认为兴趣.责任感.毅力对技能的获得非常重要. 因为我从小五音不全.肢体不协调,所以看春晚等节目的时候会把更多的关注点放在主持人身上.小时候觉得 ...
- Unity Shaderlab: Object Outlines 转
转 https://willweissman.wordpress.com/tutorials/shaders/unity-shaderlab-object-outlines/ Unity Shader ...
- Practical Node.js (2018版) 第7章:Boosting Node.js and Mongoose