power-assert-match
assert-match empowered.
Short example
const arrayOf type = assertmatchers const nums = 1 2 'x' const expectedType = 'number' assert // AssertionError: # test/power-assert-match.spec.js:30//// assert.deepEqual({ nums: nums }, { nums: arrayOf(type(expectedType)) })// | | | | | |// | | | | | "number"// | | | | TypeMatcher{expected:"number"}// | | | ArrayOfMatcher{expected:#TypeMatcher#}// | | Object{nums:#ArrayOfMatcher#}// | [1,2,"x"]// Object{nums:#Array#}//// + expected - actual//// {// "nums": [// 1// 2// - "x"// + {// + "[typeof]": "number"// + }// ]// }
Installation
npm install power-assert-match
Usage
Usage of power-assert-match
is quite similar to that of
power-assert
:
- require
power-assert-match
const assert =
- use it
const loose = assertmatchersconst actual = a: 1 b: 2const expected = a: 10assert
- to get descriptive messages like one in the example above you need to
transform your code using one of
power-assert
instrumentors:
- espower-loader (with intelli-espower-loader)
- babel-preset-power-assert
- babel-plugin-espower
- espowerify
- webpack-espower-loader.
- espower-cli
- grunt-espower
- gulp-espower
- karma-espower-preprocessor
- espower-coffee
- espower-typescript
- espower-traceur
Note, that unlike for power-assert
, where require('assert')
calls are
substituted by the instrumentors with require('power-assert')
, to use
power-assert-match
you need to require it directly.
After applying transform you get the following output:
assert | | | | | Objecta:10 | LooseMatcherexpected:#Object# Objecta:1b:2
More output examples
assert | | | | | 5 5 NotMatcherexpected:5 assert | | | | | /^\d+$/ "555f" RegexMatcherexpected:/^\d+$/ assert | | | | || | | | | | | | || | | 10 | | | | || 5 LtMatcherexpected:10 | | | | |GtMatcherexpected:5 | | | | #GtMatcher##LtMatcher# | | | EveryMatcherexpected:#Array# | 15 Objectval:#EveryMatcher# Objectval:15 assert | | | | | Objectb:5 | LooseMatcherexpected:#Object# Objecta:1b:2c:3 assert | | | | | 5 | ContainsMatcherexpected:5 123 assert | | | | | "[object Arguments]" | PrimitiveMatcherexpected:"[object Arguments]" Object{} assert | | | Objecta:1b:3c:5 Objecta:1b:2c:3