ChaiAssertionError

About

Instances of this class are attached to the .error property of a MochaTest when an assertion fails. They can be accessed from the fail event callback of a MochaReporterDelegate.

The source code for MochaHtmlReporter is a good example of how to use this class.

Properties

.actual

.actual : any

The property of .value that was actually asserted. Usually this is undefined. A case where it will be defined, for example, is if we have a blob with a size of 10 and make the following assertion:

Formula(This.expect($blob).to.have.size(27))

.customMessage

.customMessage : Text

The custom failure message passed to the assertion, if any.


In such a case, .value would be $blob, .expected would be 27, and .actual would be 10.

.expected

.expected : any

The value expected by the assertion. If an assertion does not take a value (e.g. .empty, .null, etc.), this will be undefined.


.message

.message : Text

A message explaining in detail why the assertion failed.


.showDiff

.showDiff : Boolean

True if the error is one which could display the difference between the target value and the asserted value.


.source

.source : Text

If there was an error executing an assertion formula, this will contain the source of the formula.

Example

// This code has a syntax error. There should be a closing parens
// after $blob and one less closing parens at the end of the formula.
Formula(This.expect($blob.to.have.size(27)))

// When this test is run, the .source property will contain:
This.expect($1.to.have.size(27))

.value

.value : any

The target value that was passed to .expect().

Last Updated:
Contributors: Aparajita