errors.test.ts
619 Bytes
import { describe, expect, it } from 'vitest';
import { createErrorResponse, AppError } from './errors.js';
describe('error helpers', () => {
it('builds a structured error response', () => {
expect(createErrorResponse('TEST_ERROR', '失败')).toEqual({
error: {
code: 'TEST_ERROR',
message: '失败',
},
});
});
it('stores app error metadata', () => {
const error = new AppError('TEST_ERROR', '失败', 409, { foo: 'bar' });
expect(error.code).toBe('TEST_ERROR');
expect(error.statusCode).toBe(409);
expect(error.details).toEqual({ foo: 'bar' });
});
});