2016-10-10 20:30:30 +03:00
|
|
|
var errors = require('../../server/errors'),
|
|
|
|
should = require('should');
|
|
|
|
|
|
|
|
should.equal(true, true);
|
|
|
|
|
|
|
|
describe('Errors', function () {
|
2016-10-19 17:27:22 +03:00
|
|
|
it('Ensure we inherit from Error', function () {
|
|
|
|
var ghostError = new errors.GhostError();
|
|
|
|
(ghostError instanceof Error).should.eql(true);
|
|
|
|
});
|
|
|
|
|
2016-10-10 20:30:30 +03:00
|
|
|
describe('Inherite from other error', function () {
|
|
|
|
it('default', function () {
|
|
|
|
var someError = new Error(), ghostError;
|
|
|
|
|
|
|
|
someError.message = 'test';
|
|
|
|
someError.context = 'test';
|
|
|
|
someError.help = 'test';
|
|
|
|
|
|
|
|
ghostError = new errors.GhostError({err: someError});
|
2017-01-23 14:04:01 +03:00
|
|
|
ghostError.stack.should.match(/Error: test/);
|
2016-10-10 20:30:30 +03:00
|
|
|
ghostError.context.should.eql(someError.context);
|
|
|
|
ghostError.help.should.eql(someError.help);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has nested object', function () {
|
|
|
|
var someError = new Error(), ghostError;
|
|
|
|
|
|
|
|
someError.obj = {
|
|
|
|
a: 'b'
|
|
|
|
};
|
|
|
|
|
|
|
|
ghostError = new errors.GhostError({
|
|
|
|
err: someError
|
|
|
|
});
|
|
|
|
|
|
|
|
ghostError.obj.should.eql(someError.obj);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('with custom attribute', function () {
|
|
|
|
var someError = new Error(), ghostError;
|
|
|
|
|
|
|
|
someError.context = 'test';
|
|
|
|
|
|
|
|
ghostError = new errors.GhostError({
|
|
|
|
err: someError,
|
|
|
|
context: 'context'
|
|
|
|
});
|
|
|
|
|
|
|
|
ghostError.context.should.eql('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('with custom attribute', function () {
|
|
|
|
var someError = new Error(), ghostError;
|
|
|
|
|
|
|
|
ghostError = new errors.GhostError({
|
|
|
|
err: someError,
|
2017-01-23 14:04:01 +03:00
|
|
|
message: 'test'
|
2016-10-10 20:30:30 +03:00
|
|
|
});
|
|
|
|
|
2017-01-23 14:04:01 +03:00
|
|
|
ghostError.message.should.eql('test');
|
2016-10-10 20:30:30 +03:00
|
|
|
});
|
2016-11-09 11:13:50 +03:00
|
|
|
|
|
|
|
it('error is string', function () {
|
|
|
|
var ghostError = new errors.GhostError({
|
|
|
|
err: 'string'
|
|
|
|
});
|
|
|
|
|
2017-01-23 14:04:01 +03:00
|
|
|
ghostError.stack.should.match(/Error: string/);
|
2016-11-09 11:13:50 +03:00
|
|
|
});
|
2016-10-10 20:30:30 +03:00
|
|
|
});
|
|
|
|
});
|