| | import { startOfWeek } from "./startOfWeek"; |
| |
|
| | describe("startOfWeek", () => { |
| | test("should return Monday when given a Monday", () => { |
| | const monday = new Date(2024, 2, 18); |
| | const result = startOfWeek(monday); |
| | expect(result.getDay()).toBe(1); |
| | expect(result.toISOString()).toBe(monday.toISOString()); |
| | }); |
| |
|
| | test("should return previous Monday when given a Wednesday", () => { |
| | const wednesday = new Date(2024, 2, 20); |
| | const result = startOfWeek(wednesday); |
| | const expected = new Date(2024, 2, 18); |
| | expect(result.toISOString()).toBe(expected.toISOString()); |
| | }); |
| |
|
| | test("should return previous Monday when given a Sunday", () => { |
| | const sunday = new Date(2024, 2, 24); |
| | const result = startOfWeek(sunday); |
| | const expected = new Date(2024, 2, 18); |
| | expect(result.toISOString()).toBe(expected.toISOString()); |
| | }); |
| |
|
| | test("should handle month boundaries correctly", () => { |
| | const saturday = new Date(2024, 2, 2); |
| | const result = startOfWeek(saturday); |
| | const expected = new Date(2024, 1, 26); |
| | expect(result.toISOString()).toBe(expected.toISOString()); |
| | }); |
| |
|
| | test("should handle year boundaries correctly", () => { |
| | const wednesday = new Date(2024, 0, 3); |
| | const result = startOfWeek(wednesday); |
| | const expected = new Date(2024, 0, 1); |
| | expect(result.toISOString()).toBe(expected.toISOString()); |
| | }); |
| | }); |
| |
|