power-assert-match
assert-match empowered.
Short example
import assert from 'power-assert-match'
const { arrayOf, type } = assert.matchers
const nums = [ 1, 2, 'x' ]
const expectedType = 'number'
assert.deepEqual({ nums: nums }, { nums: arrayOf(type(expectedType)) })
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 = require('power-assert-match')
- use it
const { loose } = assert.matchers
const actual = { a: 1, b: 2 }
const expected = { a: 10 }
assert.deepEqual(actual, loose(expected))
- to get descriptive messages like one in the example above you need to
transform your code using one of
power-assert
instrumentors:
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.deepEqual(actual, loose(expected))
| | |
| | Object{a:10}
| LooseMatcher{expected:#Object#}
Object{a:1,b:2}
More output examples
assert.deepEqual(val, not(val))
| | |
| | 5
5 NotMatcher{expected:5}
assert.deepEqual(number, regex(numRegex))
| | |
| | /^\d+$/
"555f" RegexMatcher{expected:/^\d+$/}
assert.deepEqual({ val: a }, { val: every([gt(b), lt(c)]) })
| | | | || | | |
| | | | || | | 10
| | | | || 5 LtMatcher{expected:10}
| | | | |GtMatcher{expected:5}
| | | | [#GtMatcher#,#LtMatcher#]
| | | EveryMatcher{expected:#Array#}
| 15 Object{val:#EveryMatcher#}
Object{val:15}
assert.deepEqual(actual, loose(expected))
| | |
| | Object{b:5}
| LooseMatcher{expected:#Object#}
Object{a:1,b:2,c:3}
assert.deepEqual(array, contains(val))
| | |
| | 5
| ContainsMatcher{expected:5}
[1,2,3]
assert.deepEqual(obj, primitive(prim))
| | |
| | "[object Arguments]"
| PrimitiveMatcher{expected:"[object Arguments]"}
Object{}
assert.deepEqual(actual, expected)
| |
| Object{a:1,b:3,c:5}
Object{a:1,b:2,c:3}
Related projects