ZonedDateTime.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. describe("errors", () => {
  2. test("called without new", () => {
  3. expect(() => {
  4. Temporal.ZonedDateTime();
  5. }).toThrowWithMessage(
  6. TypeError,
  7. "Temporal.ZonedDateTime constructor must be called with 'new'"
  8. );
  9. });
  10. test("out-of-range epoch nanoseconds value", () => {
  11. expect(() => {
  12. new Temporal.ZonedDateTime(8_640_000_000_000_000_000_001n);
  13. }).toThrowWithMessage(
  14. RangeError,
  15. "Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
  16. );
  17. expect(() => {
  18. new Temporal.ZonedDateTime(-8_640_000_000_000_000_000_001n);
  19. }).toThrowWithMessage(
  20. RangeError,
  21. "Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
  22. );
  23. });
  24. });
  25. describe("normal behavior", () => {
  26. test("length is 2", () => {
  27. expect(Temporal.ZonedDateTime).toHaveLength(2);
  28. });
  29. test("basic functionality", () => {
  30. const timeZone = new Temporal.TimeZone("UTC");
  31. const zonedDateTime = new Temporal.ZonedDateTime(0n, timeZone);
  32. expect(typeof zonedDateTime).toBe("object");
  33. expect(zonedDateTime).toBeInstanceOf(Temporal.ZonedDateTime);
  34. expect(Object.getPrototypeOf(zonedDateTime)).toBe(Temporal.ZonedDateTime.prototype);
  35. });
  36. });