-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHerror.test.ts
More file actions
42 lines (37 loc) · 1.33 KB
/
Herror.test.ts
File metadata and controls
42 lines (37 loc) · 1.33 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
import { Herror } from '../src';
describe('Herror', () => {
it('formats stack traces with module@version', () => {
const err = new Herror('hello there');
expect(err.stack).toBeDefined();
// Stack should contain at least one <module>@<version> path (e.g. from test runner)
expect(err.stack).toMatch(/\w+@[\d.]+\//);
});
it('includes an ISO date string', () => {
const err = new Herror('hello there');
const badge = new Date().toISOString().replace(/\..*$/, '');
expect(err.stack!.match(badge)?.[0]).toBe(badge);
});
it('includes the current node version', () => {
const err = new Herror('hello there');
const badge = 'node-' + process.version;
expect(err.stack!.match(badge)?.[0]).toBe(badge);
});
it('includes the current working directory', () => {
const err = new Herror('hello there');
const badge = process.cwd();
expect(err.stack!.match(badge)?.[0]).toBe(badge);
});
it('behaves as a normal Error when thrown and caught', () => {
let caught: Herror | undefined;
try {
throw new Herror('oops');
} catch (err) {
caught = err as Herror;
}
expect(caught).toBeDefined();
expect(caught!.name).toBe('Herror');
expect(caught!.message).toBe('oops');
expect(caught!).toBeInstanceOf(Error);
expect(caught!).toBeInstanceOf(Herror);
});
});