|
| 1 | +import timezone_mock, { TimeZone } from "timezone-mock"; |
| 2 | +import { getHoliday } from "./getHoliday"; |
| 3 | + |
| 4 | +const timezones: TimeZone[] = [ |
| 5 | + "US/Pacific", |
| 6 | + "US/Eastern", |
| 7 | + "Brazil/East", |
| 8 | + "UTC", |
| 9 | + "Europe/London", |
| 10 | + "Australia/Adelaide", |
| 11 | +]; |
| 12 | + |
| 13 | +afterEach(() => { |
| 14 | + timezone_mock.unregister(); |
| 15 | +}); |
| 16 | + |
| 17 | +describe("test getHoliday", () => { |
| 18 | + describe.each(timezones)("%p", (timezone) => { |
| 19 | + timezone_mock.register(timezone); |
| 20 | + |
| 21 | + it(`should return holiday for a holiday date object`, () => { |
| 22 | + const expectedHoliday = { |
| 23 | + celebrationDate: "2018-01-01", |
| 24 | + date: "2018-01-01", |
| 25 | + name: { en: "New Year's Day", es: "Año Nuevo" }, |
| 26 | + nextMonday: false, |
| 27 | + }; |
| 28 | + const holiday = getHoliday(new Date("2018-01-01")); |
| 29 | + expect(holiday).toEqual(expectedHoliday); |
| 30 | + }); |
| 31 | + |
| 32 | + it(`should return holiday with values as dates for a holiday date object`, () => { |
| 33 | + const expectedHoliday = { |
| 34 | + celebrationDate: new Date("2018-01-01T00:00:00.000Z"), |
| 35 | + date: new Date("2018-01-01T00:00:00.000Z"), |
| 36 | + name: { en: "New Year's Day", es: "Año Nuevo" }, |
| 37 | + nextMonday: false, |
| 38 | + }; |
| 39 | + const holiday = getHoliday(new Date("2018-01-01"), { |
| 40 | + valueAsDate: true, |
| 41 | + }); |
| 42 | + expect(holiday).toEqual(expectedHoliday); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + it(`should return false for a non holiday date object`, () => { |
| 47 | + expect(getHoliday(new Date("2018-01-02T05:00:00.000Z"))).toBe(null); |
| 48 | + }); |
| 49 | +}); |
0 commit comments