power-assert-match
v0.1.5
Published
power + assert-match >:3
Downloads
16
Maintainers
Readme
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)) })
// 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 = 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:
- 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.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}