|
| 1 | +import { describe, it, expect } from "vitest" |
| 2 | +import { addMonth } from "../addMonth" |
| 3 | +process.env.TZ = "America/New_York" |
| 4 | + |
| 5 | +describe("addMonth", () => { |
| 6 | + it("gets the next month on the first", () => { |
| 7 | + expect(addMonth("2022-01-01").toISOString()).toBe( |
| 8 | + "2022-02-01T05:00:00.000Z" |
| 9 | + ) |
| 10 | + }) |
| 11 | + it("can overflow a month month when the next month has fewer days", () => { |
| 12 | + expect(addMonth("2000-01-31", 1, true).toISOString()).toBe( |
| 13 | + "2000-03-02T05:00:00.000Z" |
| 14 | + ) |
| 15 | + }) |
| 16 | + it("goe to the same day of the month on the next month", () => { |
| 17 | + expect(addMonth("2000-06-04").toISOString()).toBe( |
| 18 | + "2000-07-04T04:00:00.000Z" |
| 19 | + ) |
| 20 | + }) |
| 21 | + |
| 22 | + it("can add multiple months by passing a second argument", () => { |
| 23 | + expect(addMonth("2000-01-01", 2).toISOString()).toBe( |
| 24 | + "2000-03-01T05:00:00.000Z" |
| 25 | + ) |
| 26 | + }) |
| 27 | + |
| 28 | + it("can add years months by passing a second argument", () => { |
| 29 | + expect(addMonth("2000-01-01", 25).toISOString()).toBe( |
| 30 | + "2002-02-01T05:00:00.000Z" |
| 31 | + ) |
| 32 | + }) |
| 33 | + it("can prevent month overflow with third argument", () => { |
| 34 | + expect(addMonth("2020-01-31", 1, false).toISOString()).toBe( |
| 35 | + "2020-02-29T05:00:00.000Z" |
| 36 | + ) |
| 37 | + }) |
| 38 | +}) |
0 commit comments