forked from Speedup-lib/nodejs-standard-error-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication_error.spec.ts
More file actions
59 lines (45 loc) · 1.83 KB
/
application_error.spec.ts
File metadata and controls
59 lines (45 loc) · 1.83 KB
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
import { ApplicationError } from './application_error';
describe('ApplicationError', () => {
it('check inheritance tree', () => {
const err = new ApplicationError();
expect(err instanceof Error).toBeTruthy();
expect(err instanceof ApplicationError).toBeTruthy();
});
it('should set default error message', () => {
const err = new ApplicationError();
expect(err).toHaveProperty('message');
expect(typeof err.message).toBe('string');
expect(err.message).toBe('ApplicationError');
});
it('should set custom error message', () => {
const err = new ApplicationError('MyErrorMessage');
expect(err).toHaveProperty('message');
expect(typeof err.message).toBe('string');
expect(err.message).toBe('MyErrorMessage');
});
it('should set default error code', () => {
const err = new ApplicationError();
expect(err).toHaveProperty('code');
expect(typeof err.code).toBe('string');
expect(err.code).toBe('E_APPLICATION_ERROR');
});
it('should set custom error code', () => {
const err = new ApplicationError(undefined, { code: 'E_CUSTOM_ERROR' });
expect(err).toHaveProperty('code');
expect(typeof err.code).toBe('string');
expect(err.code).toBe('E_CUSTOM_ERROR');
});
it('should set default cause (undefined)', () => {
const err = new ApplicationError();
expect(err).toHaveProperty('cause');
expect(typeof err.cause).toBe('undefined');
expect(err.cause).toBe(undefined);
});
it('should set custom cause (another application error)', () => {
const cause = new ApplicationError(undefined, { code: 'E_CAUSE' });
const err = new ApplicationError(undefined, { cause });
expect(err).toHaveProperty('cause');
expect(err.cause instanceof ApplicationError).toBeTruthy();
expect((err.cause as ApplicationError).code).toBe('E_CAUSE');
});
});