Every test framework sits on a small layer of assertions: functions that check one fact and throw when it is false. The quality of that layer decides how fast a failure can be fixed. "AssertionError: Expected 3, got 2" points straight at the bug; "false is not true" sends you to a debugger.
Write a small assertion library in assert.js: an error class, a helper that turns values into readable text, and five assertions on an assert object.
new AssertionError(message, actual, expected) is an Error with name"AssertionError", that message, and the two values kept as error.actual and error.expected.
format(value): strings, arrays and other non-null objects go through JSON.stringify; -0 becomes "-0"; anything else goes through String.
assert.ok(value) fails for every falsy value. Default message: Expected a truthy value, got <value>.
assert.equal(actual, expected) compares with Object.is: NaN equals NaN, 0 does not equal -0, two objects are equal only when they are the same object. Default message: Expected <expected>, got <actual>.
assert.notEqual fails exactly when equal would pass. Default message: Expected a value other than <expected>.
assert.deepEqual compares arrays and objects by content at every depth: the same own enumerable keys (in any order, as Object.keys lists them), arrays of the same length, each pair of values deep equal, and leaves compared with Object.is. An array never equals a non-array. A hole is a missing key, so [ , 1] differs from [undefined, 1], and [] differs from new Array(1). Default message: Expected <expected> (deep), got <actual>.
assert.throws(fn) fails when fn returns, with the message Expected the function to throw. It counts any thrown value, undefined included.
With ErrorType, the thrown value must be an instance of it (a subclass counts). Otherwise the message is Expected <type>, got <name>, where <type> is ErrorType.name and <name> is the thrown value's name property, or format(value) when it has none.
assert.throws called without a function throws a TypeError with the message assert.throws expects a function (a mistake in the test, not a failed assertion).
In every message, <value>, <actual> and <expected> stand for format of that value.