refactor(logging): replace console usage in auth flows
This commit is contained in:
27
utils/__tests__/error.test.ts
Normal file
27
utils/__tests__/error.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { normalizeError } from '../error';
|
||||
|
||||
describe('normalizeError', () => {
|
||||
it('returns the same error instance when provided', () => {
|
||||
const error = new Error('test');
|
||||
expect(normalizeError(error)).toBe(error);
|
||||
});
|
||||
|
||||
it('converts strings into Error instances', () => {
|
||||
const result = normalizeError('failure');
|
||||
expect(result).toBeInstanceOf(Error);
|
||||
expect(result.message).toBe('failure');
|
||||
});
|
||||
|
||||
it('stringifies objects when creating the error message', () => {
|
||||
const result = normalizeError({ reason: 'timeout', code: 504 });
|
||||
expect(result.message).toBe('{"reason":"timeout","code":504}');
|
||||
});
|
||||
|
||||
it('falls back to a generic error for unserializable input', () => {
|
||||
const circular: Record<string, unknown> = {};
|
||||
circular.self = circular;
|
||||
|
||||
const result = normalizeError(circular);
|
||||
expect(result.message).toBe('Unknown error');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user