To "declassify" and quote a substitution value used in a
details`...` template literal, enclose that substitution expression
in a call to quote. This makes the value appear quoted
(as if with JSON.stringify) in the message of the thrown error. The
payload itself is still passed unquoted to the console as it would be
without quote.
For example, the following will reveal the expected sky color, but not the
actual incorrect sky color, in the thrown error's message:
sky.color === expectedColor || Fail`${sky.color} should be ${quote(expectedColor)}`;
The normal convention is to locally rename details to X and quote to q
like const { details: X, quote: q } = assert;, so the above example would then be
sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;
To "declassify" and quote a substitution value used in a
details`...`
template literal, enclose that substitution expression in a call toquote
. This makes the value appear quoted (as if withJSON.stringify
) in the message of the thrown error. The payload itself is still passed unquoted to the console as it would be withoutquote
.For example, the following will reveal the expected sky color, but not the actual incorrect sky color, in the thrown error's message:
The normal convention is to locally rename
details
toX
andquote
toq
likeconst { details: X, quote: q } = assert;
, so the above example would then be