Extensible assertions.
(require("xassert"))(ref, nameopt) → {Assertion}
Creates and returns a value assertion
Example
const assert = require('xassert')
assert(4).isANumber()
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ref |
* | actual value, promise or function | |
name |
string |
<optional> |
alias for the actual value |
Returns:
new assertion instance
- Type
- Assertion
Methods
(static) fail(message) → {void}
Example
const assert = require('xassert')
assert.fail('Ops!') // This line will throw an AssertionError
Parameters:
Name | Type | Description |
---|---|---|
message |
string | message for the AssertionError constructor |
Returns:
- Type
- void
(static) fn(test) → {Assertion}
Support function to easily create tests. If the editor supports
JSDOC comments it will assist you.
Example
const isABanana = assert.fn(it => it.isEqualTo('BANANA'))
// same as "const isABanana = it => it.isEqualTo('BANANA')"
const object = { a:'BANANA', b:'APPLE' }
isABanana(assert('BANANA'))
assert(object)
.includesProperty('a', isABanana) // Passes
.includesProperty('b', isABanana) // Fails
Parameters:
Name | Type | Description |
---|---|---|
test |
assertionCallback | test |
Returns:
return the same test
- Type
- Assertion