24 lines
814 B
JavaScript
24 lines
814 B
JavaScript
|
|
import { describe, expect, it } from 'vitest';
|
||
|
|
|
||
|
|
import { formatDate } from '../../../resources/js/lib/format.js';
|
||
|
|
|
||
|
|
describe('formatDate', () => {
|
||
|
|
it('returns an em dash for empty values', () => {
|
||
|
|
expect(formatDate('')).toBe('—');
|
||
|
|
expect(formatDate(null)).toBe('—');
|
||
|
|
expect(formatDate(undefined)).toBe('—');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('returns the raw value when it is not a valid date', () => {
|
||
|
|
expect(formatDate('not-a-date')).toBe('not-a-date');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('formats valid ISO dates for display', () => {
|
||
|
|
const result = formatDate('2026-10-26T12:30:00.000000Z');
|
||
|
|
|
||
|
|
// Locale- and timezone-tolerant: only assert the stable date parts.
|
||
|
|
expect(result).toMatch(/Oct\s+26,\s+2026/);
|
||
|
|
expect(result).not.toBe('2026-10-26T12:30:00.000000Z');
|
||
|
|
});
|
||
|
|
});
|