-
-
Notifications
You must be signed in to change notification settings - Fork 737
/
Copy patherror.js
32 lines (25 loc) · 845 Bytes
/
error.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const subs = require('../utils').template
/**
* Assertion errors, can provide a detailed error messages.
*
* inspect() and cliMessage() added to display errors with params.
*/
function AssertionFailedError(params, template) {
this.params = params
this.template = template
// this.message = "AssertionFailedError";
// this.showDiff = true;
// @todo cut assert things nicer
this.showDiff = true
this.actual = this.params.actual
this.expected = this.params.expected
this.inspect = () => {
const params = this.params || {}
const msg = params.customMessage || ''
return msg + subs(this.template, params)
}
this.cliMessage = () => this.inspect()
}
AssertionFailedError.prototype = Object.create(Error.prototype)
AssertionFailedError.constructor = AssertionFailedError
module.exports = AssertionFailedError