Skip to content

Commit 0c441d9

Browse files
tests(@nestjs/core) increase errors test-cov
1 parent 8aff546 commit 0c441d9

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

src/core/errors/test/exception-handler.spec.ts renamed to src/core/test/errors/test/exception-handler.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as sinon from 'sinon';
22
import { expect } from 'chai';
3-
import { ExceptionHandler } from '../exception-handler';
4-
import { RuntimeException } from '../exceptions/runtime.exception';
5-
import { InvalidMiddlewareException } from '../exceptions/invalid-middleware.exception';
3+
import { ExceptionHandler } from '../../../errors/exception-handler';
4+
import { RuntimeException } from '../../../errors/exceptions/runtime.exception';
5+
import { InvalidMiddlewareException } from '../../../errors/exceptions/invalid-middleware.exception';
66

77
describe('ExceptionHandler', () => {
88
let instance: ExceptionHandler;

src/core/errors/test/exceptions-zone.spec.ts renamed to src/core/test/errors/test/exceptions-zone.spec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as sinon from 'sinon';
22
import { expect } from 'chai';
3-
import { ExceptionsZone } from '../exceptions-zone';
4-
import { UNHANDLED_RUNTIME_EXCEPTION } from '../messages';
3+
import { ExceptionsZone } from '../../../errors/exceptions-zone';
4+
import { UNHANDLED_RUNTIME_EXCEPTION } from '../../../errors/messages';
55

66
describe('ExceptionsZone', () => {
77
describe('run', () => {
@@ -31,4 +31,30 @@ describe('ExceptionsZone', () => {
3131
});
3232
});
3333
});
34+
describe('asyncRun', () => {
35+
let callback: sinon.SinonSpy;
36+
beforeEach(() => {
37+
callback = sinon.spy();
38+
});
39+
it('should call callback', async () => {
40+
await ExceptionsZone.asyncRun(callback as any);
41+
expect(callback.called).to.be.true;
42+
});
43+
describe('when callback throws exception', () => {
44+
const exceptionHandler = {
45+
handle: () => {},
46+
};
47+
let handleSpy: sinon.SinonSpy;
48+
beforeEach(() => {
49+
(ExceptionsZone as any).exceptionHandler = exceptionHandler;
50+
handleSpy = sinon.spy(exceptionHandler, 'handle');
51+
});
52+
it('should call "handle" method of exceptionHandler and throws UNHANDLED_RUNTIME_EXCEPTION', async () => {
53+
const throwsCallback = () => {
54+
throw 3;
55+
};
56+
expect(ExceptionsZone.asyncRun(throwsCallback)).to.eventually.be.rejected;
57+
});
58+
});
59+
});
3460
});

0 commit comments

Comments
 (0)