local-date.spec.ts 801 Bytes
Newer Older
sod-ext's avatar
sod-ext committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import { LocalDate } from './local-date';

describe('LocalDate', () => {
  const LOCAL_DATE = new LocalDate('2020-10-06');

  it('should return the month', () => {
    expect(LOCAL_DATE.getMonth()).toBe(10);
  });
  it('should return the year', () => {
    expect(LOCAL_DATE.getYear()).toBe(2020);
  });
  it('should return the day', () => {
    expect(LOCAL_DATE.getDay()).toBe(6);
  });
  it('cannot create a date with bad iso format', () => {
    expect(() => new LocalDate('20-aa-06')).toThrow('The date is malformed.');
  });
  it('should display the date in human format', () => {
    expect(LOCAL_DATE.toHumanFormat()).toBe('06/10/2020');
  });
  it("cannot create a date which doesn't exist", () => {
    expect(() => new LocalDate('2020-02-31')).toThrow("The date doesn't exist.");
  });
});