test(frontend): add unit spec for extractErrorCode
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
20
frontend/src/lib/shared/api.server.spec.ts
Normal file
20
frontend/src/lib/shared/api.server.spec.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { extractErrorCode } from './api.server';
|
||||
|
||||
describe('extractErrorCode', () => {
|
||||
it('returns the code string when error has a code property', () => {
|
||||
expect(extractErrorCode({ code: 'DOCUMENT_NOT_FOUND' })).toBe('DOCUMENT_NOT_FOUND');
|
||||
});
|
||||
it('returns undefined when error is undefined', () => {
|
||||
expect(extractErrorCode(undefined)).toBeUndefined();
|
||||
});
|
||||
it('returns undefined when error is null', () => {
|
||||
expect(extractErrorCode(null)).toBeUndefined();
|
||||
});
|
||||
it('returns undefined when error is a plain string', () => {
|
||||
expect(extractErrorCode('oops')).toBeUndefined();
|
||||
});
|
||||
it('returns undefined when error object has no code property', () => {
|
||||
expect(extractErrorCode({ message: 'fail' })).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user