-
Notifications
You must be signed in to change notification settings - Fork 9
Description
A Description object is provided to a matcher's describeTo and describeMismatch methods (see custom matchers for details). It provides the following methods to help creating consistent and detailed error descriptions:
-
append(text): Appends the given text to the description -
appendValue(value): Appends the given value to the description while trying to maintain as much information in the final output as possible. For example strings ("15") can be differentiated from numbers (<15>), functions are described by their name, arrays describe their content and general objects are converted to JSON, if possible. -
appendList(start, separator, end, list): Appends a list of values or self-describing objects (see below).For example to describe a tuple:
description.appendList('(', ', ', ')', tuple);
-
appendDescriptionOf(selfDescribing): Appends self-describing objects (i.e. anything that has adescribeTomethod, such as a matcher) to the description. -
indented(fn)(available since 3.0): Callsfnand increases the indentation level for everything that's appended byfn. Returns the result offn.This can be used to indent the description of a sub-matcher to make it easier to decipher complex messages:
… describeMismatch(actual, description) { description.append('My submatcher thinks something went wrong: '); return description.indented(() => mySubMatcher.describeMismatch(actual, description)); }
If
fnreturns a promise, everything that's appended todescriptionuntil the promise is resolved/rejected will be indented.