1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 00:15:06 +00:00
serenity/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.from.js
Linus Groh b9093dd0ab LibJS: Don't validate time zone name when parsing Instant string
This is normative change in the Temporal spec.

See: 2a81fbc
2022-01-13 10:08:34 +01:00

35 lines
1.2 KiB
JavaScript

describe("correct behavior", () => {
test("length is 1", () => {
expect(Temporal.Instant.from).toHaveLength(1);
});
test("Instant instance argument", () => {
const instant = new Temporal.Instant(123n);
expect(Temporal.Instant.from(instant).epochNanoseconds).toBe(123n);
});
test("ZonedDateTime instance argument", () => {
const timeZone = new Temporal.TimeZone("UTC");
const zonedDateTime = new Temporal.ZonedDateTime(123n, timeZone);
expect(Temporal.Instant.from(zonedDateTime).epochNanoseconds).toBe(123n);
});
test("Instant string argument", () => {
expect(Temporal.Instant.from("1975-02-02T14:25:36.123456789Z").epochNanoseconds).toBe(
160583136123456789n
);
// Time zone is not validated
expect(
Temporal.Instant.from("1975-02-02T14:25:36.123456789Z[Custom/TimeZone]")
.epochNanoseconds
).toBe(160583136123456789n);
});
});
describe("errors", () => {
test("invalid instant string", () => {
expect(() => {
Temporal.Instant.from("foo");
}).toThrowWithMessage(RangeError, "Invalid instant string 'foo'");
});
});