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

相关文章
readme-assert
readme-assert是什么 什么是readme-assert,Run code blocks in your readme as test readme-assert官网:官网 readme-assert源码仓库:源码仓库 read...
2018-11-26
assert-order
assert-order是什么 什么是assert-order,[![NPM version][npm-image]][npm-url] [![NPM downloads][downloads-image]][downloads-url] ...
2018-10-26
babel-plugin-empower-assert
babel-plugin-empower-assert是什么 什么是babel-plugin-empower-assert,Babel plugin to convert assert to power-assert at compile ...
2018-10-02
unist-util-assert
unist-util-assert是什么 什么是unist-util-assert,Assert Unist nodes unist-util-assert官网:官网 unist-util-assert源码仓库:源码仓库 unist-ut...
2018-11-13
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
assertik
assertik是什么 什么是assertik,Very simple assertion library for node and browser assertik官网:官网 assertik源码仓库:源码仓库 assertik下载地址...
2018-10-20
assert-rejects
assert-rejects是什么 什么是assert-rejects,Assert that a promise eventually rejects assert-rejects官网:官网 assert-rejects源码仓库:源码仓...
2019-01-15
assert-plus
assert-plus是什么 什么是assert-plus,Extra assertions on top of node's assert module assert-plus官网:官网 assert-plus源码仓库:源码仓库 ass...
2018-12-20
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-plugin-jsdoc-to-assert
babel-plugin-jsdoc-to-assert是什么 什么是babel-plugin-jsdoc-to-assert,Babel plugin convert jsdoc to assertion. babel-plugin-j...
2018-10-02
回到顶部