PlainTime.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. describe("errors", () => {
  2. test("called without new", () => {
  3. expect(() => {
  4. Temporal.PlainTime();
  5. }).toThrowWithMessage(
  6. TypeError,
  7. "Temporal.PlainTime constructor must be called with 'new'"
  8. );
  9. });
  10. test("cannot pass Infinity", () => {
  11. for (let i = 0; i < 6; ++i) {
  12. const args = Array(6).fill(0);
  13. args[i] = Infinity;
  14. expect(() => {
  15. new Temporal.PlainTime(...args);
  16. }).toThrowWithMessage(RangeError, "Invalid plain time");
  17. args[i] = -Infinity;
  18. expect(() => {
  19. new Temporal.PlainTime(...args);
  20. }).toThrowWithMessage(RangeError, "Invalid plain time");
  21. }
  22. });
  23. test("cannot pass invalid ISO time", () => {
  24. const badValues = [24, 60, 60, 1000, 1000, 1000];
  25. for (let i = 0; i < 6; ++i) {
  26. const args = [0, 0, 0, 0, 0, 0];
  27. args[i] = badValues[i];
  28. expect(() => {
  29. new Temporal.PlainTime(...args);
  30. }).toThrowWithMessage(RangeError, "Invalid plain time");
  31. }
  32. });
  33. });
  34. describe("normal behavior", () => {
  35. test("length is 0", () => {
  36. expect(Temporal.PlainTime).toHaveLength(0);
  37. });
  38. test("basic functionality", () => {
  39. const plainTime = new Temporal.PlainTime(19, 46, 32, 123, 456, 789);
  40. expect(typeof plainTime).toBe("object");
  41. expect(plainTime).toBeInstanceOf(Temporal.PlainTime);
  42. expect(Object.getPrototypeOf(plainTime)).toBe(Temporal.PlainTime.prototype);
  43. });
  44. });