From 5bf52382d65180f74881ca87690f615d572b8866 Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Tue, 19 Mar 2024 12:46:25 -0700 Subject: [PATCH] mock next function for test --- .../unit/controllers/agencies/agencyController.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/express-api/tests/unit/controllers/agencies/agencyController.test.ts b/express-api/tests/unit/controllers/agencies/agencyController.test.ts index bc080009f..1076e1199 100644 --- a/express-api/tests/unit/controllers/agencies/agencyController.test.ts +++ b/express-api/tests/unit/controllers/agencies/agencyController.test.ts @@ -15,6 +15,8 @@ let mockRequest: Request & MockReq, mockResponse: Response & MockRes; // const { getAgencies, addAgency, updateAgencyById, getAgencyById, deleteAgencyById } = // controllers.admin; +const _nextFunction = jest.fn(); + const _getAgencies = jest.fn().mockImplementation(() => [produceAgency()]); const _postAgency = jest.fn().mockImplementation((agency) => agency); const _getAgencyById = jest @@ -47,13 +49,13 @@ describe('UNIT - Agencies Admin', () => { describe('Controller getAgencies', () => { it('should return status 200 and a list of agencies', async () => { - await controllers.getAgencies(mockRequest, mockResponse); + await controllers.getAgencies(mockRequest, mockResponse, _nextFunction); expect(mockResponse.statusValue).toBe(200); }); it('should return status 200 and a list of agencies', async () => { _getKeycloakUserRoles.mockImplementationOnce(() => []); - await controllers.getAgencies(mockRequest, mockResponse); + await controllers.getAgencies(mockRequest, mockResponse, _nextFunction); expect(mockResponse.statusValue).toBe(200); }); @@ -63,7 +65,7 @@ describe('UNIT - Agencies Admin', () => { parentId: '0', id: '1', }; - await controllers.getAgencies(mockRequest, mockResponse); + await controllers.getAgencies(mockRequest, mockResponse, _nextFunction); expect(mockResponse.statusValue).toBe(200); }); @@ -72,7 +74,7 @@ describe('UNIT - Agencies Admin', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any name: 0 as any, }; - await controllers.getAgencies(mockRequest, mockResponse); + await controllers.getAgencies(mockRequest, mockResponse, _nextFunction); expect(mockResponse.statusValue).toBe(400); }); });