PlainDateTime.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. describe("errors", () => {
  2. test("called without new", () => {
  3. expect(() => {
  4. Temporal.PlainDateTime();
  5. }).toThrowWithMessage(
  6. TypeError,
  7. "Temporal.PlainDateTime constructor must be called with 'new'"
  8. );
  9. });
  10. test("cannot pass Infinity", () => {
  11. for (let i = 0; i < 9; ++i) {
  12. const args = Array(9).fill(0);
  13. args[i] = Infinity;
  14. expect(() => {
  15. new Temporal.PlainDateTime(...args);
  16. }).toThrowWithMessage(RangeError, "Invalid plain date time");
  17. args[i] = -Infinity;
  18. expect(() => {
  19. new Temporal.PlainDateTime(...args);
  20. }).toThrowWithMessage(RangeError, "Invalid plain date time");
  21. }
  22. });
  23. test("cannot pass invalid ISO date or time", () => {
  24. // NOTE: The year max value is 3 more than in the polyfill, but they incorrectly seem to
  25. // use ISOYearMonthWithinLimits, which AFAICT isn't used for PlainDate{,Time} in the spec.
  26. // ¯\_(ツ)_/¯
  27. const badValues = [275764, 0, 0, 24, 60, 60, 1000, 1000, 1000];
  28. for (let i = 0; i < 9; ++i) {
  29. const args = [0, 1, 1, 0, 0, 0, 0, 0, 0];
  30. args[i] = badValues[i];
  31. expect(() => {
  32. new Temporal.PlainDateTime(...args);
  33. }).toThrowWithMessage(RangeError, "Invalid plain date time");
  34. }
  35. });
  36. });
  37. describe("normal behavior", () => {
  38. test("length is 3", () => {
  39. expect(Temporal.PlainDateTime).toHaveLength(3);
  40. });
  41. test("basic functionality", () => {
  42. const plainDateTime = new Temporal.PlainDateTime(2021, 7, 22, 19, 46, 32, 123, 456, 789);
  43. expect(typeof plainDateTime).toBe("object");
  44. expect(plainDateTime).toBeInstanceOf(Temporal.PlainDateTime);
  45. expect(Object.getPrototypeOf(plainDateTime)).toBe(Temporal.PlainDateTime.prototype);
  46. });
  47. });