Assert Unist nodes.
npm:
npm install unist-util-assert
var assert = require('unist-util-assert')
assert({type: 'root', children: []})
assert({type: 'break'})
assert({type: 'element', properties: {}, children: []})
// All OK.
assert({children: []})
// AssertionError: node should have a type: `{ children: [] }`
assert.parent({type: 'break'})
// AssertionError: parent should have `children`: `{ type: 'break' }`
assert({type: 'element', properties: function() {}})
// AssertionError: non-specced property `properties` should be JSON: `{ type: 'element', properties: [Function] }`
assert.void({type: 'text', value: 'Alpha'})
// AssertionError: void should not have `value`: `{ type: 'text', value: 'Alpha' }`
assert({type: 'paragraph', children: ['foo']})
// AssertionError: node should be an object: `'foo'` in `{ type: 'paragraph', children: [ 'foo' ] }`
Assert that node
is a valid Unist node. If node
has children
,
all children will be asserted as well.
Assert that node
is a valid Unist Parent.
Assert that node
is a valid Unist Text.
Assert that node
is a valid Unist node, but neither Text nor Parent.
This module can be used as a base to test subsets of Unist (for an
example, see mdast-util-assert
). All functions
which are exposed from such a module, and functions used internally to
test child nodes, should be wrapped in assert.wrap
, which adds an
inspectable string of the respective node, and its parent when available,
to exposed error message.
Wraps a function (which is passed a node, and an optional parent node), so that any errors thrown inside it will contain information regarding the node (and the parent, when given).
mdast-util-assert
— Check mdast nodeshast-util-assert
— Check hast nodesnlcst-test
— Check nlcst nodes
See contributing.md
in syntax-tree/unist
for ways to get
started.
This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.