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-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
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
assert-diff
assert-diff是什么 什么是assert-diff,Drop-in replacement for assert to give diff on deepEqual. assert-diff官网:官网 assert-diff源码仓...
2018-09-24
simple-assert
simple-assert是什么 什么是simple-assert,Vanilla Assertions simple-assert官网:官网 simple-assert源码仓库:源码仓库 simple-assert下载地址:点此下载 点...
2018-09-21
assertion-error
assertion-error是什么 什么是assertion-error,Error constructor for test and validation frameworks that implements standardized ...
2018-09-17
assert-exception
assert-exception是什么 什么是assert-exception,Assert-exception — <p align="right"> <a href="https://...
2018-12-03
power-assert-renderer-comparison
power-assert-renderer-comparison是什么 什么是power-assert-renderer-comparison,comparison renderer for power-assert context po...
2019-01-02
回到顶部