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 ...
随机推荐
- How to Rerun Failed Tests in JUnit?
该帖转自其他出处 Sometimes due to some temporarily problems such as connection problems, server problems, br ...
- CSS的进一步深入(更新中···)
在之前我们学了6种选择器和三种CSS样式的引入,学习选择器就是为了更好的选择文本,学习CSS的引入是为了使文本增加各种样式和属性, 下面我们简单来学习一下为文本加样式和一些属性和属性值: 1.文本的样 ...
- Flask学习【第1篇】:Flask介绍
Flask介绍(轻量级的框架,非常快速的就能把程序搭建起来) Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是So ...
- SpringBoot 整合携程Apollo配置管理中心
携程官网对apollo的使用讲解了很多种方式的使用,但是感觉一些细节还是没讲全,特别是eureka配置中心地址的配置 这里对springboot整合apollo说一下 >SpringBoot启动 ...
- newcoder F石头剪刀布(DFS + 思维)题解
题意:wzms 今年举办了一场剪刀石头布大赛,bleaves 被选为负责人. 比赛共有 2n 个人参加, 分为 n 轮, 在每轮中,第 1 位选手和第 2 位选手对战,胜者作为新的第 1 位选手, 第 ...
- 大明A+B(大数相加)解题报告
Problem Description 话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫"大明". 这时他已经不是那个只会做100以内加法的那个"小明 ...
- (转)mblog解读(二)
(二期)12.开源博客项目mblog解读(二) [课程12]freema...模板.xmind77.9KB [课程12]hibernat...arch.xmind0.1MB freemarker模板技 ...
- 配置和运行 MatchNet CVPR 2015 MatchNet: Unifying Feature and Metric Learning for Patch-Based Matching
配置和运行 MatchNet CVPR 2015 GitHub: https://github.com/hanxf/matchnet 最近一个同学在配置,测试这个网络,但是总是遇到各种问题. 我也尝试 ...
- 【ASP.Net】publish asp.net to local IIS
做web项目难免要将项目部署, 要么部署在azure上,要么部署在本地, 使用IIS去host. 部署步骤很简单, 1. vs打开你的web项目, 项目名上面右键选择publish 2. 在弹出的pu ...
- SAP 财务模块 FI-TV 差旅管理
SAP 财务模块 FI-TV 差旅管理 Travel Management差旅管理事务码 描述PRT3 Trip Costs: Maintain Postings ...
- Practical Node.js (2018版) 第7章:Boosting Node.js and Mongoose