UNPKG

kenya-holidays

Version:

A simple package to retrieve all Kenyan public holidays for a given year

94 lines (77 loc) 4.1 kB
// Tests for kenya-holidays package const { getKenyanHolidays, getDetailedKenyanHolidays } = require('./index'); describe('Kenya Holidays Package', () => { describe('getKenyanHolidays', () => { test('should return all holidays for the specified year', () => { const holidays = getKenyanHolidays(2025); // Check if all fixed holidays are present expect(holidays["New Year's Day"]).toBeInstanceOf(Date); expect(holidays["Labour Day"]).toBeInstanceOf(Date); expect(holidays["Madaraka Day"]).toBeInstanceOf(Date); expect(holidays["Huduma Day"]).toBeInstanceOf(Date); expect(holidays["Mashujaa Day"]).toBeInstanceOf(Date); expect(holidays["Jamhuri Day"]).toBeInstanceOf(Date); expect(holidays["Christmas Day"]).toBeInstanceOf(Date); expect(holidays["Boxing Day"]).toBeInstanceOf(Date); expect(holidays["Utamaduni Day"]).toBeInstanceOf(Date); // Check if Easter-dependent holidays are present expect(holidays["Good Friday"]).toBeInstanceOf(Date); expect(holidays["Easter Monday"]).toBeInstanceOf(Date); // Check if variable holidays have the expected string values expect(typeof holidays["Eid al-Fitr*"]).toBe('string'); expect(typeof holidays["Eid al-Adha*"]).toBe('string'); }); test('should correctly calculate Easter-based holidays', () => { // Test 2023 Easter dates (Easter Sunday was April 9, 2023) const holidays2023 = getKenyanHolidays(2023, true); expect(holidays2023["Good Friday"]).toBe('2023-04-07'); expect(holidays2023["Easter Monday"]).toBe('2023-04-10'); // Test 2024 Easter dates (Easter Sunday is March 31, 2024) const holidays2024 = getKenyanHolidays(2024, true); expect(holidays2024["Good Friday"]).toBe('2024-03-29'); expect(holidays2024["Easter Monday"]).toBe('2024-04-01'); // Test 2025 Easter dates (Easter Sunday will be April 20, 2025) const holidays2025 = getKenyanHolidays(2025, true); expect(holidays2025["Good Friday"]).toBe('2025-04-18'); expect(holidays2025["Easter Monday"]).toBe('2025-04-21'); // Test 2026 Easter dates (Easter Sunday will be April 5, 2026) const holidays2026 = getKenyanHolidays(2026, true); expect(holidays2026["Good Friday"]).toBe('2026-04-03'); expect(holidays2026["Easter Monday"]).toBe('2026-04-06'); }); test('should format dates correctly when formatted=true', () => { const holidays = getKenyanHolidays(2025, true); expect(holidays["New Year's Day"]).toBe('2025-01-01'); expect(holidays["Labour Day"]).toBe('2025-05-01'); expect(holidays["Christmas Day"]).toBe('2025-12-25'); }); test('should default to current year when no year is provided', () => { const holidays = getKenyanHolidays(); const currentYear = new Date().getFullYear(); expect(holidays["New Year's Day"].getFullYear()).toBe(currentYear); expect(holidays["Christmas Day"].getFullYear()).toBe(currentYear); }); }); describe('getDetailedKenyanHolidays', () => { test('should return detailed holiday information', () => { const detailedHolidays = getDetailedKenyanHolidays(2025); // Check structure of a fixed holiday const newYear = detailedHolidays.find(h => h.name === "New Year's Day"); expect(newYear).toBeDefined(); expect(newYear.date).toBe('2025-01-01'); expect(newYear.type).toBe('National'); expect(newYear.description).toBeTruthy(); expect(newYear.isVariable).toBe(false); // Check structure of a variable holiday const eid = detailedHolidays.find(h => h.name === "Eid al-Fitr*"); expect(eid).toBeDefined(); expect(eid.isVariable).toBe(true); // Check that holidays are sorted by date const sortedDates = detailedHolidays .filter(h => !h.isVariable) .map(h => h.date); const sortedCopy = [...sortedDates].sort(); expect(sortedDates).toEqual(sortedCopy); }); }); });