test: update outdated unit test

This commit is contained in:
Kamil Myśliwiec
2024-11-18 09:56:13 +01:00
parent 9129e4f858
commit 47941ba4d9

View File

@@ -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;
});
});
});