LibJS: Implement Temporal.PlainMonthDay/YearMonth.prototype.toPlainDate

This commit is contained in:
Timothy Flynn 2024-11-22 19:36:23 -05:00 committed by Andreas Kling
commit 46998e922a
Notes: github-actions[bot] 2024-11-23 13:47:30 +00:00
6 changed files with 127 additions and 0 deletions

View file

@ -0,0 +1,27 @@
describe("normal behavior", () => {
test("length is 1", () => {
expect(Temporal.PlainMonthDay.prototype.toPlainDate).toHaveLength(1);
});
test("basic functionality", () => {
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
const plainDate = plainMonthDay.toPlainDate({ year: 2021 });
expect(plainDate.equals(new Temporal.PlainDate(2021, 7, 6))).toBeTrue();
});
});
describe("errors", () => {
test("argument must be an object", () => {
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
expect(() => {
plainMonthDay.toPlainDate(42);
}).toThrowWithMessage(TypeError, "42 is not an object");
});
test("year field is required", () => {
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
expect(() => {
plainMonthDay.toPlainDate({});
}).toThrowWithMessage(TypeError, "Required property year is missing or undefined");
});
});

View file

@ -0,0 +1,27 @@
describe("normal behavior", () => {
test("length is 1", () => {
expect(Temporal.PlainYearMonth.prototype.toPlainDate).toHaveLength(1);
});
test("basic functionality", () => {
const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
const plainDate = plainYearMonth.toPlainDate({ day: 6 });
expect(plainDate.equals(new Temporal.PlainDate(2021, 7, 6))).toBeTrue();
});
});
describe("errors", () => {
test("argument must be an object", () => {
const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
expect(() => {
plainYearMonth.toPlainDate(42);
}).toThrowWithMessage(TypeError, "42 is not an object");
});
test("day field is required", () => {
const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
expect(() => {
plainYearMonth.toPlainDate({});
}).toThrowWithMessage(TypeError, "Required property day is missing or undefined");
});
});