Instant.from.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. describe("correct behavior", () => {
  2. test("length is 1", () => {
  3. expect(Temporal.Instant.from).toHaveLength(1);
  4. });
  5. test("Instant instance argument", () => {
  6. const instant = new Temporal.Instant(123n);
  7. expect(Temporal.Instant.from(instant).epochNanoseconds).toBe(123n);
  8. });
  9. test("ZonedDateTime instance argument", () => {
  10. const timeZone = new Temporal.TimeZone("UTC");
  11. const zonedDateTime = new Temporal.ZonedDateTime(123n, timeZone);
  12. expect(Temporal.Instant.from(zonedDateTime).epochNanoseconds).toBe(123n);
  13. });
  14. test("Instant string argument", () => {
  15. expect(Temporal.Instant.from("1975-02-02T14:25:36.123456789Z").epochNanoseconds).toBe(
  16. 160583136123456789n
  17. );
  18. // Time zone is not validated
  19. expect(
  20. Temporal.Instant.from("1975-02-02T14:25:36.123456789Z[Custom/TimeZone]")
  21. .epochNanoseconds
  22. ).toBe(160583136123456789n);
  23. });
  24. });
  25. describe("errors", () => {
  26. test("invalid instant string", () => {
  27. expect(() => {
  28. Temporal.Instant.from("foo");
  29. }).toThrowWithMessage(RangeError, "Invalid instant string 'foo'");
  30. });
  31. });