测试工作——Assent 断言模板
2016-01-20 19:21
253 查看
Assert 断言模块
This module is used for writing unit tests for your applications, you can access it withrequire('assert').
断言(Assert)模块用于为应用编写单元测试,可以通过
require('assert')对该模块进行调用。
assert.fail(actual, expected, message, operator)
Tests ifactualis equal to
expectedusing the operator provided.
使用指定操作符测试
actual(真实值)是否和
expected(期望值)一致。
assert.ok(value, [message])
Tests if value is atruevalue, it is equivalent to
assert.equal(true, value, message);
测试实际值是否为
true,和
assert.equal(true, value, message);作用一致
assert.equal(actual, expected, [message])
Tests shallow, coercive equality with the equal comparison operator (==).
使用等值比较操作符(
==)测试真实值是否浅层地(shallow),强制性地(coercive)和预期值相等。
assert.notEqual(actual, expected, [message])
Tests shallow, coercive non-equality with the not equal comparison operator (!=).
使用不等比较操作符(
!=)测试真实值是否浅层地(shallow),强制性地(coercive)和预期值不相等。
assert.deepEqual(actual, expected, [message])
Tests for deep equality.测试真实值是否深层次地和预期值相等。
assert.notDeepEqual(actual, expected, [message])
Tests for any deep inequality.测试真实值是否深层次地和预期值不相等。
assert.strictEqual(actual, expected, [message])
Tests strict equality, as determined by the strict equality operator (===)
使用严格相等操作符 (
===)测试真实值是否严格地(strict)和预期值相等。
assert.notStrictEqual(actual, expected, [message])
Tests strict non-equality, as determined by the strict not equal operator (!==)
使用严格不相等操作符 (
!==)测试真实值是否严格地(strict)和预期值不相等。
assert.throws(block, [error], [message])
Expectsblockto throw an error.
errorcan be constructor, regexp or validation function.
预期
block时抛出一个错误(error),
error可以为构造函数,正则表达式或者其他验证器。
Validate instanceof using constructor:
使用构造函数验证实例:
assert.throws( function() { throw new Error("Wrong value"); }, Error);
Validate error message using RegExp:
使用正则表达式验证错误信息:
assert.throws( function() { throw new Error("Wrong value"); }, /value/);
Custom error validation:
用户自定义的错误验证器:
assert.throws( function() { throw new Error("Wrong value"); }, function(err) { if ( (err instanceof Error) && /value/.test(err) ) { return true; } }, "unexpected error");
assert.doesNotThrow(block, [error], [message])
Expectsblocknot to throw an error, see assert.throws for details.
预期
block时不抛出错误,详细信息请见assert.throws。
assert.ifError(value)
Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument,errorin callbacks.
测试值是否不为false,当为true时抛出。常用于回调中第一个参数
error的测试。 - 一介布衣
转自:http://yijiebuyi.com/blog/ca2c0edf447624bd4d527490c9fce369.html
相关文章推荐
- intent.putExtra()方法参数详解
- Qt中文乱码问题
- Android Manifest.xml详解
- 获取时间戳和随机数
- Django实现文件上传下载
- CodeForces 173C Spiral Maximum 记忆化搜索 滚动数组优化
- 29 Servlet/JSP中用到的模式 MVC 模式,
- 前端ajax传值后台接收并写入数据库
- Universal-Image-Loader,android-Volley,Picasso、Fresco和Glide五大Android开源组件加载网络图片比较
- phpstorm使用技巧
- 使用druid连接池的超时回收机制排查连接泄露问题
- hdu2032
- Java--时间处理
- moon 28 Servlet其他文件上传技术对比
- leetcode--Reverse integer
- zhu的工作日记:带移动提示的seekBar的Demo(android)
- Alcatraz ----The package manager for Xcode
- ucos 和uclinux的区别及各自的特点
- firefox下 js 生成 form submit提交问题
- 27 Servlet文件上传技术