assert

2019-01-13 admin

assert是什么

什么是assert,commonjs assert - node.js api compatible

assert使用教程帮助文档

assert

Build Status

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

It aims to be fully compatibe with the node.js assert module, same API and same behavior, just adding support for web browsers. The API and code may contain traces of the CommonJS Unit Testing 1.0 spec which they were based on, but both have evolved significantly since then.

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

Throws an exception that displays the values for actual and expected separated by the provided operator.

assert(value, message), assert.ok(value, [message])

Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message);

assert.equal(actual, expected, [message])

Tests shallow, coercive equality with the equal comparison operator ( == ).

assert.notEqual(actual, expected, [message])

Tests shallow, coercive non-equality with the not equal comparison operator ( != ).

assert.deepEqual(actual, expected, [message])

Tests for deep equality.

assert.deepStrictEqual(actual, expected, [message])

Tests for deep equality, as determined by the strict equality operator ( === )

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 ( === )

assert.notStrictEqual(actual, expected, [message])

Tests strict non-equality, as determined by the strict not equal operator ( !== )

assert.throws(block, [error], [message])

Expects block to throw an error. error can be constructor, regexp or validation function.

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, [message])

Expects block not to throw an error, see assert.throws for details.

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.

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-50856.html

文章标题:assert

相关文章
assert-diff
assert-diff是什么 什么是assert-diff,Drop-in replacement for assert to give diff on deepEqual. assert-diff官网:官网 assert-diff源码仓...
2018-09-24
minimalistic-assert
minimalistic-assert是什么 什么是minimalistic-assert,minimalistic-assert === minimalistic-assert官网:官网 minimalistic-assert源码仓库:...
2018-11-02
empower-assert
empower-assert是什么 什么是empower-assert,Convert assert to power-assert on ESTree AST empower-assert官网:官网 empower-assert源码仓库...
2018-09-20
jsdoc-to-assert
jsdoc-to-assert是什么 什么是jsdoc-to-assert,Convert comment to assert. runtime assert jsdoc-to-assert官网:官网 jsdoc-to-assert源码仓...
2018-10-02
assert-dir-equal
assert-dir-equal是什么 什么是assert-dir-equal,Assert that the contents of two directories are equal. assert-dir-equal官网:官网 as...
2018-11-15
在与摩卡JavaScript测试assert.equal和assert.deepequal之间的区别吗?
mshell_lauren提出了一个问题:The difference between assert.equal and assert.deepEqual in Javascript testing with Mocha?,或许与您遇到的问...
2018-03-29
babel-preset-power-assert
babel-preset-power-assert是什么 什么是babel-preset-power-assert,Babel preset for all power-assert plugins babel-preset-power-...
2018-10-02
babel-preset-jsdoc-to-assert
babel-preset-jsdoc-to-assert是什么 什么是babel-preset-jsdoc-to-assert,babel preset for jsdoc-to-assert babel-preset-jsdoc-to-...
2018-10-02
assertit
assertit是什么 什么是assertit,Thin sugar layer on top of testit framework, is-kindof and assert. assertit官网:官网 assertit源码仓库:源...
2018-09-27
回到顶部