Duration.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. describe("errors", () => {
  2. test("called without new", () => {
  3. expect(() => {
  4. Temporal.Duration();
  5. }).toThrowWithMessage(TypeError, "Temporal.Duration constructor must be called with 'new'");
  6. });
  7. test("cannot mix arguments with different signs", () => {
  8. expect(() => {
  9. new Temporal.Duration(-1, 1);
  10. }).toThrowWithMessage(RangeError, "Invalid duration");
  11. expect(() => {
  12. new Temporal.Duration(1, -1);
  13. }).toThrowWithMessage(RangeError, "Invalid duration");
  14. });
  15. test("cannot pass Infinity", () => {
  16. expect(() => {
  17. new Temporal.Duration(Infinity);
  18. }).toThrowWithMessage(RangeError, "Invalid duration");
  19. });
  20. });
  21. describe("normal behavior", () => {
  22. test("length is 0", () => {
  23. expect(Temporal.Duration).toHaveLength(0);
  24. });
  25. test("basic functionality", () => {
  26. const duration = new Temporal.Duration();
  27. expect(typeof duration).toBe("object");
  28. expect(duration).toBeInstanceOf(Temporal.Duration);
  29. expect(Object.getPrototypeOf(duration)).toBe(Temporal.Duration.prototype);
  30. });
  31. });