1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 15:24:57 +00:00
serenity/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.js
Luke Wilde 1e829c4ea8 LibJS: Check PlainMonthDay is in the ISO date time limits in creation
This is a normative change in the Temporal spec.

See: 374305c
2022-07-22 17:10:03 +01:00

65 lines
2.4 KiB
JavaScript

describe("errors", () => {
test("called without new", () => {
expect(() => {
Temporal.PlainMonthDay();
}).toThrowWithMessage(
TypeError,
"Temporal.PlainMonthDay constructor must be called with 'new'"
);
});
test("cannot pass Infinity", () => {
expect(() => {
new Temporal.PlainMonthDay(Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain month day");
expect(() => {
new Temporal.PlainMonthDay(1, Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain month day");
expect(() => {
new Temporal.PlainMonthDay(1, 1, {}, Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain month day");
expect(() => {
new Temporal.PlainMonthDay(-Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain month day");
expect(() => {
new Temporal.PlainMonthDay(1, -Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain month day");
expect(() => {
new Temporal.PlainMonthDay(1, 1, {}, -Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain month day");
});
test("cannot pass invalid ISO month/day", () => {
expect(() => {
new Temporal.PlainMonthDay(0, 1);
}).toThrowWithMessage(RangeError, "Invalid plain month day");
expect(() => {
new Temporal.PlainMonthDay(1, 0);
}).toThrowWithMessage(RangeError, "Invalid plain month day");
});
test("not within iso date time limit", () => {
expect(() => {
new Temporal.PlainMonthDay(9, 30, "iso8601", 999_999_999_999_999);
}).toThrowWithMessage(RangeError, "Invalid plain month day");
});
});
describe("normal behavior", () => {
test("length is 2", () => {
expect(Temporal.PlainMonthDay).toHaveLength(2);
});
test("basic functionality", () => {
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
expect(typeof plainMonthDay).toBe("object");
expect(plainMonthDay).toBeInstanceOf(Temporal.PlainMonthDay);
expect(Object.getPrototypeOf(plainMonthDay)).toBe(Temporal.PlainMonthDay.prototype);
});
test("default reference year is 1972", () => {
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
const fields = plainMonthDay.getISOFields();
expect(fields.isoYear).toBe(1972);
});
});