mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
test: update outdated unit test
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import * as sinon from 'sinon';
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import { ExceptionHandler } from '../../../errors/exception-handler';
|
||||
import { RuntimeException } from '../../../errors/exceptions/runtime.exception';
|
||||
import { InvalidMiddlewareException } from '../../../errors/exceptions/invalid-middleware.exception';
|
||||
|
||||
describe('ExceptionHandler', () => {
|
||||
let instance: ExceptionHandler;
|
||||
@@ -10,7 +9,7 @@ describe('ExceptionHandler', () => {
|
||||
instance = new ExceptionHandler();
|
||||
});
|
||||
describe('handle', () => {
|
||||
let logger;
|
||||
let logger: { error: Function };
|
||||
let errorSpy: sinon.SinonSpy;
|
||||
beforeEach(() => {
|
||||
logger = {
|
||||
@@ -19,16 +18,10 @@ describe('ExceptionHandler', () => {
|
||||
(ExceptionHandler as any).logger = logger;
|
||||
errorSpy = sinon.spy(logger, 'error');
|
||||
});
|
||||
it('when exception is instanceof RuntimeException', () => {
|
||||
it('should call the logger.error method with the thrown exception passed as an argument', () => {
|
||||
const exception = new RuntimeException('msg');
|
||||
instance.handle(exception);
|
||||
expect(errorSpy.calledWith(exception.message, exception.stack)).to.be
|
||||
.true;
|
||||
});
|
||||
it('when exception is not instanceof RuntimeException', () => {
|
||||
const exception = new InvalidMiddlewareException('msg');
|
||||
instance.handle(exception);
|
||||
expect(errorSpy.calledWith(exception.what(), exception.stack)).to.be.true;
|
||||
expect(errorSpy.calledWith(exception)).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user