index.test.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { getLunarFestivals } from "../../src";
  2. describe("lunarFestivals", () => {
  3. test("getLunarFestivals should return fixed lunar festivals", () => {
  4. // 测试常规固定节日
  5. const result = getLunarFestivals("2025-01-29");
  6. expect(result).toEqual([
  7. {
  8. date: "2025-01-29",
  9. name: ["春节", "鸡日", "元始天尊诞辰"],
  10. }
  11. ]);
  12. });
  13. test("should handle solar term related festivals", () => {
  14. // 测试寒食节(清明前一日)
  15. const result = getLunarFestivals("2025-04-03");
  16. expect(result).toEqual([{
  17. date: "2025-04-03",
  18. name: ["寒食节"],
  19. }]);
  20. });
  21. test("should handle special festivals", () => {
  22. // 测试除夕(农历腊月最后一日)
  23. const result = getLunarFestivals("2025-01-28");
  24. expect(result).toEqual([{
  25. date: "2025-01-28",
  26. name: ["除夕", "封井", "祭井神", "贴春联", "迎财神"],
  27. }]);
  28. });
  29. test("should filter leap month festivals", () => {
  30. const result1 = getLunarFestivals("2025-06-30")
  31. expect(result1).toEqual([{
  32. date: "2025-06-30",
  33. name: ["晒衣节"],
  34. }]);
  35. // 测试闰月不返回节日
  36. const result2 = getLunarFestivals("2025-07-30")
  37. expect(result2).toEqual([]);
  38. });
  39. test("should handle cross-year scenarios", () => {
  40. // 测试多天与跨年场景
  41. const result = getLunarFestivals("2024-11-15", "2025-01-30");
  42. expect(result).toEqual([
  43. {
  44. date: "2024-11-15",
  45. name: ["下元节", "水官诞辰"],
  46. },
  47. {
  48. date: "2025-01-07",
  49. name: ["腊八节"],
  50. },
  51. {
  52. date: "2025-01-22",
  53. name: ["官家送灶"],
  54. },
  55. {
  56. date: "2025-01-23",
  57. name: ["民间送灶"],
  58. },
  59. {
  60. date: "2025-01-24",
  61. name: ["接玉皇"],
  62. },
  63. {
  64. date: "2025-01-28",
  65. name: ["除夕", "封井", "祭井神", "贴春联", "迎财神"],
  66. },
  67. {
  68. date: "2025-01-29",
  69. name: ["春节", "鸡日", "元始天尊诞辰"],
  70. },
  71. {
  72. date: "2025-01-30",
  73. name: ["犬日"],
  74. },
  75. ]);
  76. });
  77. });