mirror of
https://github.com/chaijs/chai
synced 2024-11-15 08:17:14 +00:00
49 lines
No EOL
1.1 KiB
JavaScript
49 lines
No EOL
1.1 KiB
JavaScript
/*!
|
|
* chai
|
|
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
|
* MIT Licensed
|
|
*/
|
|
|
|
var fail = require('./chai').fail;
|
|
|
|
module.exports = AssertionError;
|
|
|
|
/*!
|
|
* Inspired by node.js assert module
|
|
* https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
|
|
*/
|
|
function AssertionError (options) {
|
|
options = options || {};
|
|
this.name = 'AssertionError';
|
|
this.message = options.message;
|
|
this.actual = options.actual;
|
|
this.expected = options.expected;
|
|
this.operator = options.operator;
|
|
var stackStartFunction = options.stackStartFunction || fail;
|
|
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, stackStartFunction);
|
|
}
|
|
}
|
|
|
|
AssertionError.prototype.__proto__ = Error.prototype;
|
|
|
|
AssertionError.prototype.summary = function() {
|
|
var str = '';
|
|
|
|
if (this.operator) {
|
|
str += 'In: \'' + this.operator + '\'\n\t';
|
|
}
|
|
|
|
str += '' + this.name + (this.message ? ': ' + this.message : '');
|
|
|
|
return str;
|
|
};
|
|
|
|
AssertionError.prototype.details = function() {
|
|
return this.summary();
|
|
};
|
|
|
|
AssertionError.prototype.toString = function() {
|
|
return this.summary();
|
|
}; |