forked from redis/node-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_errors.spec.js
89 lines (81 loc) · 3.3 KB
/
custom_errors.spec.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
'use strict';
var assert = require('assert');
var errors = require('../lib/customErrors');
describe('errors', function () {
describe('AbortError', function () {
it('should inherit from Error', function () {
var e = new errors.AbortError({});
assert.strictEqual(e.message, '');
assert.strictEqual(e.name, 'AbortError');
assert.strictEqual(Object.keys(e).length, 0);
assert(e instanceof Error);
assert(e instanceof errors.AbortError);
});
it('should list options properties but not name and message', function () {
var e = new errors.AbortError({
name: 'weird',
message: 'hello world',
property: true
});
assert.strictEqual(e.message, 'hello world');
assert.strictEqual(e.name, 'weird');
assert.strictEqual(e.property, true);
assert.strictEqual(Object.keys(e).length, 2);
assert(e instanceof Error);
assert(e instanceof errors.AbortError);
assert(delete e.name);
assert.strictEqual(e.name, 'AbortError');
});
it('should change name and message', function () {
var e = new errors.AbortError({
message: 'hello world',
property: true
});
assert.strictEqual(e.name, 'AbortError');
assert.strictEqual(e.message, 'hello world');
e.name = 'foo';
e.message = 'foobar';
assert.strictEqual(e.name, 'foo');
assert.strictEqual(e.message, 'foobar');
});
});
describe('AggregateError', function () {
it('should inherit from Error and AbortError', function () {
var e = new errors.AggregateError({});
assert.strictEqual(e.message, '');
assert.strictEqual(e.name, 'AggregateError');
assert.strictEqual(Object.keys(e).length, 0);
assert(e instanceof Error);
assert(e instanceof errors.AggregateError);
assert(e instanceof errors.AbortError);
});
it('should list options properties but not name and message', function () {
var e = new errors.AggregateError({
name: 'weird',
message: 'hello world',
property: true
});
assert.strictEqual(e.message, 'hello world');
assert.strictEqual(e.name, 'weird');
assert.strictEqual(e.property, true);
assert.strictEqual(Object.keys(e).length, 2);
assert(e instanceof Error);
assert(e instanceof errors.AggregateError);
assert(e instanceof errors.AbortError);
assert(delete e.name);
assert.strictEqual(e.name, 'AggregateError');
});
it('should change name and message', function () {
var e = new errors.AggregateError({
message: 'hello world',
property: true
});
assert.strictEqual(e.name, 'AggregateError');
assert.strictEqual(e.message, 'hello world');
e.name = 'foo';
e.message = 'foobar';
assert.strictEqual(e.name, 'foo');
assert.strictEqual(e.message, 'foobar');
});
});
});