forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions-zone.spec.ts
More file actions
34 lines (33 loc) · 1.26 KB
/
Copy pathexceptions-zone.spec.ts
File metadata and controls
34 lines (33 loc) · 1.26 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
import * as sinon from 'sinon';
import { expect } from 'chai';
import { ExceptionsZone } from '../exceptions-zone';
import { UNHANDLED_RUNTIME_EXCEPTION } from '../messages';
describe('ExceptionsZone', () => {
describe('run', () => {
let callback: sinon.SinonSpy;
beforeEach(() => {
callback = sinon.spy();
});
it('should call callback', () => {
ExceptionsZone.run(callback as any);
expect(callback.called).to.be.true;
});
describe('when callback throws exception', () => {
const exceptionHandler = {
handle: () => {},
};
let handleSpy: sinon.SinonSpy;
beforeEach(() => {
(ExceptionsZone as any).exceptionHandler = exceptionHandler;
handleSpy = sinon.spy(exceptionHandler, 'handle');
});
it('should call "handle" method of exceptionHandler and throws UNHANDLED_RUNTIME_EXCEPTION', () => {
const throwsCallback = () => {
throw 3;
};
expect(() => ExceptionsZone.run(throwsCallback)).to.throws(UNHANDLED_RUNTIME_EXCEPTION);
expect(handleSpy.called).to.be.true;
});
});
});
});