Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib/DateAssertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class DateAssertion extends Assertion<Date> {
}

/**
* 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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/lib/DateAssertion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down