Files
directus/api/src/utils/async-handler.test.ts
Rijk van Zanten d68ec5fda7 Cleanup imports (#19966)
* Cleanup imports

* Add changeset
2023-10-09 15:17:29 -04:00

21 lines
701 B
TypeScript

import type { RequestHandler, Request, Response } from 'express';
import '../types/express.d.ts';
import asyncHandler from './async-handler.js';
import { expect, vi, test } from 'vitest';
let mockRequest: Partial<Request & { token?: string }>;
let mockResponse: Partial<Response>;
const nextFunction = vi.fn();
test('Wraps async middleware in Promise resolve that will catch rejects and pass them to the nextFn', async () => {
const err = new Error('testing');
const middleware: RequestHandler = async (_req, _res, _next) => {
throw err;
};
await asyncHandler(middleware)(mockRequest as Request, mockResponse as Response, nextFunction);
expect(nextFunction).toHaveBeenCalledWith(err);
});