chai/lib/error.js
2012-05-06 07:01:34 -04:00

59 lines
1.1 KiB
JavaScript

/*!
* chai
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
* MIT Licensed
*/
/*!
* Main export
*/
module.exports = AssertionError;
/**
* # AssertionError (constructor)
*
* Create a new assertion error based on the Javascript
* `Error` prototype.
*
* **Options**
* - message
* - actual
* - expected
* - operator
* - startStackFunction
*
* @param {Object} options
* @api public
*/
function AssertionError (options) {
options = options || {};
this.message = options.message;
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
if (options.stackStartFunction && Error.captureStackTrace) {
var stackStartFunction = options.stackStartFunction;
Error.captureStackTrace(this, stackStartFunction);
}
}
/*!
* Inherit from Error
*/
AssertionError.prototype = Object.create(Error.prototype);
AssertionError.prototype.name = 'AssertionError';
AssertionError.prototype.constructor = AssertionError;
/**
* # toString()
*
* Override default to string method
*/
AssertionError.prototype.toString = function() {
return this.message;
};