-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.js
106 lines (81 loc) · 3.74 KB
/
test.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var NestedError = require('./index.js');
var expect = require('chai').expect;
var uuid = require('uuid');
var inherits = require('util').inherits;
describe('NestedErrors', function () {
it('are instances of Error', function () {
var error = new NestedError();
expect(error).to.be.an.instanceOf(Error);
expect(error).to.be.an.instanceOf(NestedError);
});
it('include message in stacktrace', function () {
var message = uuid.v1();
var nested = new NestedError(message);
expect(nested.stack).to.contain(message);
});
it('includes child stack in stacktrace', function () {
var childMessage = uuid.v1();
var child = new Error(childMessage);
var message = uuid.v1();
var nested = new NestedError(message, child);
expect(nested.stack).to.contain('Caused By: ' + child.stack);
});
it('allows multiple nested errors', function () {
var childMessage = uuid.v1();
var child = new Error(childMessage);
var child2Message = uuid.v1();
var child2 = new NestedError(child2Message, child);
var message = uuid.v1();
var nested = new NestedError(message, child2);
expect(nested.stack).to.contain('Caused By: ' + child2.stack);
});
it('includes Error subclass names in stacks', function () {
var SubclassError = function (message) {
NestedError.call(this, message);
};
inherits(SubclassError, NestedError);
SubclassError.prototype.name = 'SubclassError';
var message = uuid.v1();
var error = new SubclassError(message);
expect(error.stack).to.contain('SubclassError');
expect(error.stack).to.contain(message);
});
it('includes Error subclass with nesting', function () {
var SubclassError = function (message, nested) {
NestedError.call(this, message, nested);
};
inherits(SubclassError, NestedError);
SubclassError.prototype.name = 'SubclassError';
var childMessage = uuid.v1();
var child = new Error(childMessage);
var message = uuid.v1();
var error = new SubclassError(message, child);
expect(error.stack).to.contain('Caused By: ' + child.stack);
});
it('messages are ECMAScript6 compatible', function () {
var nested = new NestedError(uuid.v1());
var messageDescriptor = Object.getOwnPropertyDescriptor(nested, 'message');
expect(messageDescriptor.writable).to.be.equal(true);
expect(messageDescriptor.enumerable).to.be.equal(false);
expect(messageDescriptor.configurable).to.be.equal(true);
});
it('without messages are ECMAScript6 compatible', function () {
var nested = new NestedError();
var messageDescriptor = Object.getOwnPropertyDescriptor(nested, 'message');
expect(messageDescriptor).to.be.undefined;
});
it('has stack property attributes that match other errors', function () {
var normal = new Error();
var nested = new Error('test', normal);
var normalStackDescriptor = Object.getOwnPropertyDescriptor(normal, 'stack');
var nestedStackDescriptor = Object.getOwnPropertyDescriptor(nested, 'stack');
expect(nestedStackDescriptor.enumerable, 'enumerable').to.equal(normalStackDescriptor.enumerable);
expect(nestedStackDescriptor.configurable, 'configurable').to.equal(normalStackDescriptor.configurable);
expect(nestedStackDescriptor.writable, 'writable').to.equal(normalStackDescriptor.writable);
});
it('can accept only error parameter', function () {
var error = new Error();
var nestedError = new NestedError(error);
expect(nestedError).to.be.an.instanceOf(NestedError);
});
});