Skip to content

Commit

Permalink
Add DailyLearning.getCalendars()
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Dec 27, 2024
1 parent 92ba354 commit 759762c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/DailyLearning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ export class DailyLearning {
}
return null;
}

/** Returns the names of all calendars registered */
static getCalendars(): string[] {
return Array.from(cals.keys());
}
}
18 changes: 18 additions & 0 deletions test/DailyLearning.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {expect, test} from 'vitest';
import {HDate} from '@hebcal/hdate';
import {DailyLearning} from '../src/DailyLearning';

test('DailyLearning', () => {
expect(DailyLearning.getCalendars()).toEqual([]);
const dummy = () => {return null};
const hd = new HDate();
DailyLearning.addCalendar('Foo', dummy);
DailyLearning.addCalendar('Bar', dummy);
expect(DailyLearning.getCalendars()).toEqual(['Foo', 'Bar']);
const dummy2 = () => {return {bogus: true}};
DailyLearning.addCalendar('Quux', dummy2);
expect(DailyLearning.getCalendars()).toEqual(['Foo', 'Bar', 'Quux']);
expect(DailyLearning.lookup('Foo', hd, false)).toBeNull();
expect(DailyLearning.lookup('Bar', hd, false)).toBeNull();
expect(DailyLearning.lookup('Quux', hd, false)).toEqual({bogus: true});
});

0 comments on commit 759762c

Please sign in to comment.