diff --git a/src/lib/DateAssertion.ts b/src/lib/DateAssertion.ts index 688b6949..ef573dc6 100644 --- a/src/lib/DateAssertion.ts +++ b/src/lib/DateAssertion.ts @@ -24,9 +24,9 @@ export class DateAssertion extends Assertion { } /** - * Check if a day of the week, might be string - * (e.g 'monday') or number (e.g 0-6), equals the - * day of the actual date. + * Check if a day of the week equals the day of the actual date. You can pass + * either a string (e.g. "monday"), or a number from 0 to 6, where 0 is + * Sunday and 6 is Saturday, as in Date.getDay(). * * @param dayOfWeek the day to compare with * @returns the assertion instance diff --git a/src/lib/helpers/dates.ts b/src/lib/helpers/dates.ts index 734ce742..5b0d8b55 100644 --- a/src/lib/helpers/dates.ts +++ b/src/lib/helpers/dates.ts @@ -2,13 +2,13 @@ import { DateOptions, DayOfWeek, Month } from "../DateAssertion.types"; export function dayOfWeekAsNumber (day: DayOfWeek): number { switch (day) { + case "sunday": return 0; case "monday": return 1; case "tuesday": return 2; case "wednesday": return 3; case "thursday": return 4; case "friday": return 5; case "saturday": return 6; - case "sunday": return 7; } } diff --git a/test/lib/DateAssertion.test.ts b/test/lib/DateAssertion.test.ts index a21606c6..b073275f 100644 --- a/test/lib/DateAssertion.test.ts +++ b/test/lib/DateAssertion.test.ts @@ -29,6 +29,19 @@ describe("[Unit] DateAssertion.test.ts", () => { assert.deepStrictEqual(test.not.toBeDayOfWeek(1), test); }); }); + + context("when the day of the actual date is Sunday", () => { + context('when comparing to the "sunday" literal', () => { + it("does not raise an AssertionError", () => { + const actualDate = new Date(2022, 9, 2); // October 2nd, 2022 + const test = new DateAssertion(actualDate); + + assert.doesNotThrow(() => { + test.toBeDayOfWeek("sunday"); + }, AssertionError); + }); + }); + }); }); describe(".toMatchDateParts", () => {