From 4aef438088f421a14c711d0850bf335579fd445a Mon Sep 17 00:00:00 2001 From: glebbash Date: Tue, 17 Feb 2026 12:18:53 +0000 Subject: [PATCH] fix: update tests --- .../exceptions/exceptions-handler.spec.ts | 68 ++++++++----------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/packages/core/test/exceptions/exceptions-handler.spec.ts b/packages/core/test/exceptions/exceptions-handler.spec.ts index 12a918022..e7b259ec0 100644 --- a/packages/core/test/exceptions/exceptions-handler.spec.ts +++ b/packages/core/test/exceptions/exceptions-handler.spec.ts @@ -1,14 +1,12 @@ import { HttpException } from '@nestjs/common'; -import { isNil, isObject } from '@nestjs/common/utils/shared.utils'; -import { expect } from 'chai'; -import * as createHttpError from 'http-errors'; -import * as sinon from 'sinon'; +import { isNil, isObject } from '@nestjs/common/utils/shared.utils.js'; +import createHttpError from 'http-errors'; +import { AbstractHttpAdapter } from '../../adapters/index.js'; +import { InvalidExceptionFilterException } from '../../errors/exceptions/invalid-exception-filter.exception.js'; +import { ExceptionsHandler } from '../../exceptions/exceptions-handler.js'; +import { ExecutionContextHost } from '../../helpers/execution-context-host.js'; +import { NoopHttpAdapter } from '../utils/noop-adapter.js'; import fastifyErrors from '@fastify/error'; -import { AbstractHttpAdapter } from '../../adapters'; -import { InvalidExceptionFilterException } from '../../errors/exceptions/invalid-exception-filter.exception'; -import { ExceptionsHandler } from '../../exceptions/exceptions-handler'; -import { ExecutionContextHost } from '../../helpers/execution-context-host'; -import { NoopHttpAdapter } from '../utils/noop-adapter.spec'; describe('ExceptionsHandler', () => { let adapter: AbstractHttpAdapter; @@ -64,14 +62,12 @@ describe('ExceptionsHandler', () => { )(); handler.next(fastifyError, new ExecutionContextHost([0, response])); - expect(statusStub.calledWith(400)).to.be.true; - expect( - jsonStub.calledWith({ - statusCode: 400, - message: - "Body cannot be empty when content-type is set to 'application/json'", - }), - ).to.be.true; + expect(statusStub).toHaveBeenCalledWith(400); + expect(jsonStub).toHaveBeenCalledWith({ + statusCode: 400, + message: + "Body cannot be empty when content-type is set to 'application/json'", + }); }); it('should not treat errors from external API calls as errors from "http-errors" library', () => { const apiCallError = Object.assign( @@ -80,13 +76,11 @@ describe('ExceptionsHandler', () => { ); handler.next(apiCallError, new ExecutionContextHost([0, response])); - expect(statusStub.calledWith(500)).to.be.true; - expect( - jsonStub.calledWith({ - statusCode: 500, - message: 'Internal server error', - }), - ).to.be.true; + expect(statusStub).toHaveBeenCalledWith(500); + expect(jsonStub).toHaveBeenCalledWith({ + statusCode: 500, + message: 'Internal server error', + }); }); it('should treat fastify errors as http errors', () => { const fastifyError = fastifyErrors.createError( @@ -96,14 +90,12 @@ describe('ExceptionsHandler', () => { )(); handler.next(fastifyError, new ExecutionContextHost([0, response])); - expect(statusStub.calledWith(400)).to.be.true; - expect( - jsonStub.calledWith({ - statusCode: 400, - message: - "Body cannot be empty when content-type is set to 'application/json'", - }), - ).to.be.true; + expect(statusStub).toHaveBeenCalledWith(400); + expect(jsonStub).toHaveBeenCalledWith({ + statusCode: 400, + message: + "Body cannot be empty when content-type is set to 'application/json'", + }); }); it('should not treat errors from external API calls as errors from "http-errors" library', () => { const apiCallError = Object.assign( @@ -112,13 +104,11 @@ describe('ExceptionsHandler', () => { ); handler.next(apiCallError, new ExecutionContextHost([0, response])); - expect(statusStub.calledWith(500)).to.be.true; - expect( - jsonStub.calledWith({ - statusCode: 500, - message: 'Internal server error', - }), - ).to.be.true; + expect(statusStub).toHaveBeenCalledWith(500); + expect(jsonStub).toHaveBeenCalledWith({ + statusCode: 500, + message: 'Internal server error', + }); }); describe('when exception is instantiated by "http-errors" library', () => { it('should send expected response status code and message', () => {