For asserting a boolean expression with an optional message or messages.

dessert.assert(expr, message)

On failure, ie. when expr is falsey, assert throws an exception with the specified message. On success, assert returns the namespace dessert, thus making asserts chainable.

Note that while only the first argument is used for detecting failure, any number of arguments may be passed to .assert() and all of those arguments will end up in the assertion message, in their original order.

In order to extend Dessert with your own assertions, you'll need to add validators using Dessert's API created for this specific purpose. Validators are functions that take any number of arguments, and return true if the arguments satisfy the condition, and false if they don't.

There are two ways of adding validators. The shorter one takes a method name and a validator function:

dessert.addType(methodName, validator)

However, for code clarity and aiding IDEs in identifying methods, there's another way for validator addition, where multiple functions may be batched together in a single object:

dessert.addTypes({

methodName: validator,

methodName2: validator2

});

When a user-defined assertion is invoked as dessert.methodName(), the validator is first evaluated, then its result and all arguments are passed to dessert.assert().

It is often necessary to invoke a validator from another validator, thus composing new validators out of existing ones. Existing validators may be accessed on the context object (this) of every validator added using either .addType() or .addTypes().

For each assertion our application may have to run some custom code dealing with user output or logging. A custom handler may be specified via the method .customHandler(). A custom handler may return false, preventing the assertion mechanism to throw an exception.