emi-challenge-fe/tests/app/shared/pipes/safe-date-pipe.spec.ts

39 lines
943 B
TypeScript

import { describe, it, expect, vi, afterEach } from 'vitest';
import { SafeDatePipe } from '@app/shared/pipes/safe-date-pipe';
describe('SafeDatePipe', () => {
let pipe: SafeDatePipe;
afterEach(() => {
vi.useRealTimers();
});
beforeEach(() => {
pipe = new SafeDatePipe();
});
it('should transform a date string to relative format', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-05-13T12:00:00'));
const result = pipe.transform('2026-05-13T10:00:00');
expect(result).toBe('Today');
});
it('should transform a Date object to relative format', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-05-13T12:00:00'));
const result = pipe.transform(new Date('2026-05-12T10:00:00'));
expect(result).toBe('Yesterday');
});
it('should return empty string for null value', () => {
const result = pipe.transform(null);
expect(result).toBe('');
});
});