Assertion Syntax¶
readme-assert transforms special comments in your code blocks into
assert.deepEqual() or assert.throws() calls.
Deep Equal¶
Use //=> after an expression to assert its value:
The // → (unicode arrow) and // -> (ascii arrow) variants also work:
Throws¶
Assert that an expression throws using // throws with a regex pattern:
Console Output¶
Assert console output — the call is preserved and an assertion is added:
Resolves¶
Assert that a Promise resolves to a value:
The to is optional:
This generates assert.deepEqual(await expr, value).
Rejects¶
Assert that a Promise rejects matching a pattern:
This generates await assert.rejects(() => expr, /pattern/).
What Gets Generated¶
Given:
readme-assert generates: