Instant.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. describe("errors", () => {
  2. test("called without new", () => {
  3. expect(() => {
  4. Temporal.Instant();
  5. }).toThrowWithMessage(TypeError, "Temporal.Instant constructor must be called with 'new'");
  6. });
  7. test("argument must be coercible to bigint", () => {
  8. expect(() => {
  9. new Temporal.Instant(123);
  10. }).toThrowWithMessage(TypeError, "Cannot convert number to BigInt");
  11. expect(() => {
  12. new Temporal.Instant("foo");
  13. }).toThrowWithMessage(SyntaxError, "Invalid value for BigInt: foo");
  14. });
  15. });
  16. describe("normal behavior", () => {
  17. test("length is 1", () => {
  18. expect(Temporal.Instant).toHaveLength(1);
  19. });
  20. test("basic functionality", () => {
  21. const instant = new Temporal.Instant(123n);
  22. expect(instant.epochNanoseconds).toBe(123n);
  23. expect(typeof instant).toBe("object");
  24. expect(instant).toBeInstanceOf(Temporal.Instant);
  25. expect(Object.getPrototypeOf(instant)).toBe(Temporal.Instant.prototype);
  26. });
  27. });