The code in a chapter is wrapped like so
[source,javascript]
----
// code here
----
To unit test, add the expected value after a comment, followed by ::
, like so:
[source,javascript]
----
let somevar;
somevar === undefined; //:: true
----
The //::
turns into just //
in the cleanup script and that reads fine in the final version, like:
let somevar;
somevar === undefined; // true
NaN
is a special case as it doesn't equal itself:
[source,javascript]
----
1 * undefined; //:: NaN
----
Errors can be unit-tested too, so long as they are not parsing errors:
[source,javascript]
----
foo; //:: ReferenceError:: foo is not defined
----
Extra comments for the book version can be added after ,,
and the unit testing ignores them, like:
[source,javascript]
----
let s = "100";
typeof s; //:: "string"
s = s * 1; //:: 100,, you can also use `s *= 1`
... which after the cleanup script reads nicely, like:
let s = "100";
typeof s; // "string"
s = s * 1; // 100 you can also use `s *= 1`
////--
means do not test this snippet, it's untestable, e.g. a parsing error:
[source,javascript]
----////--
const hello = 1;
let hello;
----
//--
means that the code snippet depends on the previous, so test them together, e.g.:
[source,javascript]
----
let a = 5;
a += 3; //:: 8
----
You can continue:
[source,javascript]
----//--
a -= 3; //:: 5
----
++--
means don't add "use strict";
to the snippet being tested, e.g.:
[source,javascript]
----++--
var a = 012;
a === 10; //:: true
----
/*nolint*/
means this snippet fails to lint, but we're ok with that:
[source,javascript]
----++--
/*nolint*/
var a = 012;
a === 10; //:: true
----