Power Assert in JavaScript. Provides descriptive assertion messages through standard assert interface. No API is the best API.
Power Assert in JavaScript. Provides descriptive assertion messages through standard assert interface. No API is the best API.
[![power-assert][power-assert-banner]][power-assert-url]
Power Assert in JavaScript. Provides descriptive assertion messages through standard assert interface. No API is the best API.
[![Build Status][travis-image]][travis-url] [![NPM package][npm-image]][npm-url] [![Bower package][bower-image]][bower-url] [![License][license-image]][license-url]
What is power-assert?
assert(any_expression) function)assert(any_expression).require('power-assert') any more. Keep using require('assert'), and power-assert enhances them transparently. See slides: From Library to Tool - power-assert as a General Purpose Assertion Enhancement Toolpower-assert - power = assert. Without code transpilation, power-assert works just as normal assert does.power-assert provides descriptive assertion messages for your tests, like this.
1) Array #indexOf() should return index when the value is present:
AssertionError: # path/to/test/mocha_node.js:10
assert(ary.indexOf(zero) === two)
| | | | |
| | | | 2
| -1 0 false
[1,2,3]
[number] two
=> 2
[number] ary.indexOf(zero)
=> -1
power-assert enhances these assert functions by espower. Produces descriptive message when assertion is failed.
assert(value, [message])assert.ok(value, [message])assert.equal(actual, expected, [message])assert.notEqual(actual, expected, [message])assert.strictEqual(actual, expected, [message])assert.notStrictEqual(actual, expected, [message])assert.deepEqual(actual, expected, [message])assert.notDeepEqual(actual, expected, [message])assert.deepStrictEqual(actual, expected, [message])assert.notDeepStrictEqual(actual, expected, [message])power-assert is fully compatible with assert. So functions below are also available though they are not enhanced (does not produce descriptive message).
assert.fail(actual, expected, message, operator)assert.throws(block, [error], [message])assert.doesNotThrow(block, [message])assert.ifError(value)Since version 1.5.0, power-assert supports "strict mode" as well.
power-assert provides an API for customization.
assert.customize(options)Though power-assert is fully compatible with standard assert interface, all you need to remember is just an assert(any_expression) function in most cases.
The core value of power-assert is absolute simplicity and stability. Especially, power-assert sticks to the simplest form of testing, assert(any_expression).
assert(types[index].name === bob.name)
| || | | | |
| || | | | "bob"
| || | | Person{name:"bob",age:5}
| || | false
| |11 "alice"
| Person{name:"alice",age:3}
["string",98.6,true,false,null,undefined,#Array#,#Object#,NaN,Infinity,/^not/,#Person#]
--- [string] bob.name
+++ [string] types[index].name
@@ -1,3 +1,5 @@
-bob
+alice
TypeError: assert._capt is not a functionassert calls in productionshould/expect code to power-assert?npm install --save-dev power-assert <one of instrumentors>
or
bower install --save-dev power-assert
npm install --save-dev <one of instrumentors>
See CHANGELOG
See HOW TO USE section for more details.
Note: There is an online demo site available.
…
To use power-assert, you need to transform your test code for power-assert output.
Code transform is done by instrumentors below:
No open issues yet, or sync has not completed.