Use the details function as a template literal tag to create
informative error messages. The assertion functions take such messages
as optional arguments:
assert(sky.isBlue(), details`${sky.color} should be "blue"`);
or following the normal convention to locally rename details to X
and quote to q like const { details: X, quote: q } = assert;:
assert(sky.isBlue(), X`${sky.color} should be "blue"`);
However, note that in most cases it is preferable to instead use the Fail
template literal tag (which has the same input signature as details
but automatically creates and throws an error):
sky.isBlue() || Fail`${sky.color} should be "blue"`;
The details template tag returns a DetailsToken object that can print
itself with the formatted message in two ways.
It will report full details to the console, but
mask embedded substitution values with their typeof information in the thrown error
to prevent revealing secrets up the exceptional path. In the example
above, the thrown error may reveal only that sky.color is a string,
whereas the same diagnostic printed to the console reveals that the
sky was green. This masking can be disabled for an individual substitution value
using quote.
The raw property of an input template array is ignored, so a simple
array of strings may be provided directly.
Use the
details
function as a template literal tag to create informative error messages. The assertion functions take such messages as optional arguments:or following the normal convention to locally rename
details
toX
andquote
toq
likeconst { details: X, quote: q } = assert;
:However, note that in most cases it is preferable to instead use the
Fail
template literal tag (which has the same input signature asdetails
but automatically creates and throws an error):The details template tag returns a
DetailsToken
object that can print itself with the formatted message in two ways. It will report full details to the console, but mask embedded substitution values with their typeof information in the thrown error to prevent revealing secrets up the exceptional path. In the example above, the thrown error may reveal only thatsky.color
is a string, whereas the same diagnostic printed to the console reveals that the sky was green. This masking can be disabled for an individual substitution value usingquote
.The
raw
property of an input template array is ignored, so a simple array of strings may be provided directly.