您的位置:首页 > 其它

测试工作——Assent 断言模板

2016-01-20 19:21 253 查看

Assert 断言模块

This module is used for writing unit tests for your applications, you can access it with
require('assert')
.

断言(Assert)模块用于为应用编写单元测试,可以通过
require('assert')
对该模块进行调用。

assert.fail(actual, expected, message, operator)

Tests if
actual
is equal to
expected
using the operator provided.

使用指定操作符测试
actual
(真实值)是否和
expected
(期望值)一致。

assert.ok(value, [message])

Tests if value is a
true
value, 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])

Expects
block
to throw an error.
error
can 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])

Expects
block
not 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,
error
in callbacks.

测试值是否不为false,当为true时抛出。常用于回调中第一个参数
error
的测试。 - 一介布衣

转自:http://yijiebuyi.com/blog/ca2c0edf447624bd4d527490c9fce369.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: