UNPKG

@unito/integration-sdk

Version:

Integration SDK

28 lines (27 loc) 971 B
import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; import notFound from '../../src/middlewares/notFound.js'; describe('notFound middleware', () => { it('respond with error without calling next', () => { let actualStatus; let actualJson; const response = { headersSent: false, status: (code) => { actualStatus = code; return { json: (json) => { actualJson = json; }, }; }, locals: { logger: { error: () => undefined } }, }; notFound({ path: 'unknownPath' }, response, () => { throw new Error('next should not be called'); }); assert.strictEqual(actualStatus, 404); assert.strictEqual(actualJson?.code, '404'); assert.deepEqual(actualJson?.message, 'Path unknownPath not found.'); }); });