PlainMonthDay.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. describe("errors", () => {
  2. test("called without new", () => {
  3. expect(() => {
  4. Temporal.PlainMonthDay();
  5. }).toThrowWithMessage(
  6. TypeError,
  7. "Temporal.PlainMonthDay constructor must be called with 'new'"
  8. );
  9. });
  10. test("cannot pass Infinity", () => {
  11. expect(() => {
  12. new Temporal.PlainMonthDay(Infinity);
  13. }).toThrowWithMessage(RangeError, "Invalid plain month day");
  14. expect(() => {
  15. new Temporal.PlainMonthDay(1, Infinity);
  16. }).toThrowWithMessage(RangeError, "Invalid plain month day");
  17. expect(() => {
  18. new Temporal.PlainMonthDay(1, 1, {}, Infinity);
  19. }).toThrowWithMessage(RangeError, "Invalid plain month day");
  20. expect(() => {
  21. new Temporal.PlainMonthDay(-Infinity);
  22. }).toThrowWithMessage(RangeError, "Invalid plain month day");
  23. expect(() => {
  24. new Temporal.PlainMonthDay(1, -Infinity);
  25. }).toThrowWithMessage(RangeError, "Invalid plain month day");
  26. expect(() => {
  27. new Temporal.PlainMonthDay(1, 1, {}, -Infinity);
  28. }).toThrowWithMessage(RangeError, "Invalid plain month day");
  29. });
  30. test("cannot pass invalid ISO month/day", () => {
  31. expect(() => {
  32. new Temporal.PlainMonthDay(0, 1);
  33. }).toThrowWithMessage(RangeError, "Invalid plain month day");
  34. expect(() => {
  35. new Temporal.PlainMonthDay(1, 0);
  36. }).toThrowWithMessage(RangeError, "Invalid plain month day");
  37. });
  38. });
  39. describe("normal behavior", () => {
  40. test("length is 2", () => {
  41. expect(Temporal.PlainMonthDay).toHaveLength(2);
  42. });
  43. test("basic functionality", () => {
  44. const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
  45. expect(typeof plainMonthDay).toBe("object");
  46. expect(plainMonthDay).toBeInstanceOf(Temporal.PlainMonthDay);
  47. expect(Object.getPrototypeOf(plainMonthDay)).toBe(Temporal.PlainMonthDay.prototype);
  48. });
  49. test("default reference year is 1972", () => {
  50. const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
  51. const fields = plainMonthDay.getISOFields();
  52. expect(fields.isoYear).toBe(1972);
  53. });
  54. });