UNPKG

ncc-prototype-email-alerts-sub

Version:

Northumberland Council Front End Email Alerts Subscription Prototype

43 lines (36 loc) 1.77 kB
import {errorHandlerMiddleware} from '../../middleware/globalErrorHandler' import { Request, Response } from 'express'; import { CustomError } from '../../types/custom'; let req: Partial<Request>; let res:Partial<Response>; let next: jest.Mock; // eslint-disable-next-line @typescript-eslint/no-explicit-any describe('should return error and render error pages if there is any error', () => { beforeEach(() => { req = {}; res = { redirect : jest.fn() }; next = jest.fn(); }) test('should render error500 page when there is no error status', () => { const error = new Error('test error') errorHandlerMiddleware(error, req as Request, res as Response, next) expect(res.redirect).toHaveBeenCalledWith('/error500') }) test('should render error404 page when there is error with status 404', () => { const error: CustomError = {status: 404, name: "test error", message : 'test error msg'} errorHandlerMiddleware(error, req as Request, res as Response, next) expect(res.redirect).toHaveBeenCalledWith('/error404') }) test('should render error500 page when there is error with status 500', () => { const error: CustomError = {status: 500, name: "test error", message : 'server error'} errorHandlerMiddleware(error, req as Request, res as Response, next) expect(res.redirect).toHaveBeenCalledWith('/error500') }) test('should render error500 page when there is error with status 403', () => { const error: CustomError = {status: 403, name: "test error", message : 'resource not found'} errorHandlerMiddleware(error, req as Request, res as Response, next) expect(res.redirect).toHaveBeenCalledWith('/error500') }) })