Browse Source

feat: enhance test cases

yaavi 8 months ago
parent
commit
a075963d3a
1 changed files with 14 additions and 2 deletions
  1. 14 2
      test/utils/dayjs.test.ts

+ 14 - 2
test/utils/dayjs.test.ts

@@ -3,7 +3,10 @@ import simpleDayjs from "../../src/utils/dayjs";
 
 describe("SimpleDayjs", () => {
   it("should return true for a valid date", () => {
-    const date = simpleDayjs("2024-02-10");
+    let date = simpleDayjs();
+    expect(date.isValid()).toBe(true);
+
+    date = simpleDayjs("2024-02-10");
     expect(date.isValid()).toBe(true);
   });
 
@@ -12,9 +15,11 @@ describe("SimpleDayjs", () => {
     expect(date.isValid()).toBe(false);
   });
 
-  it("should calculate the difference in days", () => {
+  it("should calculate the difference", () => {
     const date1 = simpleDayjs("2024-02-10");
     const date2 = simpleDayjs("2000-01-01");
+    expect(date1.diff(date2, "year")).toBe(24);
+    expect(date1.diff(date2, "month")).toBe(289);
     expect(date1.diff(date2, "day")).toBe(8806);
   });
 
@@ -23,6 +28,13 @@ describe("SimpleDayjs", () => {
     expect(date.startOf("year").format("YYYY-MM-DD")).toBe("2024-01-01");
   });
 
+  it("should format the end of the ...", () => {
+    const date = simpleDayjs("2024-02-10");
+    expect(date.endOf("year").format("YYYY-MM-DD HH:mm:ss")).toBe("2024-12-31 23:59:59");
+    expect(date.endOf("month").format("YYYY-MM-DD HH:mm:ss")).toBe("2024-02-29 23:59:59");
+    expect(date.endOf("day").format("YYYY-MM-DD HH:mm:ss")).toBe("2024-02-10 23:59:59");
+  });
+
   it("should add one month to the date", () => {
     const date = simpleDayjs("2024-02-10");
     expect(date.add(1, "month").format("YYYY-MM-DD")).toBe("2024-03-10");