Im trying to unit test some middleware.
export const someMiddleware = catchAsync(async (req: Request, res: Response, next: NextFunction) => {
//...
}
But it always returns undefined because of catchAsync
export const catchAsync = (fn: any) => {
return function (req: Request, res: Response, next: NextFunction) {
fn(req, res, next).catch(next);
};
};
describe('some middleware test', () => {
let mockRequest: Partial<Request>;
let mockResponse: Partial<Response>;
let nextFunction: NextFunction = jest.fn();
beforeEach(() => {
mockRequest = {};
mockResponse = {
json: jest.fn(),
};
});
test('this some throw error', async () => {
const result = await someMiddleware(mockRequest as Request, mockResponse as Response, nextFunction);
expect(result).toEqual('...');
});
});
So, what I'm missing or a keyword to resolve catchAsync?