mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:37:43 +00:00
LibJS: Implement Temporal.PlainMonthDay.prototype.toString()
This commit is contained in:
parent
c1c8d7861c
commit
ea44f33d5b
5 changed files with 101 additions and 0 deletions
|
@ -0,0 +1,36 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Temporal.PlainMonthDay.prototype.toString).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
let plainMonthDay;
|
||||
|
||||
plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
expect(plainMonthDay.toString()).toBe("07-06");
|
||||
expect(plainMonthDay.toString({ calendarName: "auto" })).toBe("07-06");
|
||||
expect(plainMonthDay.toString({ calendarName: "always" })).toBe("07-06[u-ca=iso8601]");
|
||||
expect(plainMonthDay.toString({ calendarName: "never" })).toBe("07-06");
|
||||
|
||||
plainMonthDay = new Temporal.PlainMonthDay(7, 6, { toString: () => "foo" }, 2021);
|
||||
expect(plainMonthDay.toString()).toBe("2021-07-06[u-ca=foo]");
|
||||
expect(plainMonthDay.toString({ calendarName: "auto" })).toBe("2021-07-06[u-ca=foo]");
|
||||
expect(plainMonthDay.toString({ calendarName: "always" })).toBe("2021-07-06[u-ca=foo]");
|
||||
expect(plainMonthDay.toString({ calendarName: "never" })).toBe("2021-07-06");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainMonthDay object", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainMonthDay.prototype.toString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainMonthDay");
|
||||
});
|
||||
|
||||
test("calendarName option must be one of 'auto', 'always', 'never'", () => {
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
expect(() => {
|
||||
plainMonthDay.toString({ calendarName: "foo" });
|
||||
}).toThrowWithMessage(RangeError, "foo is not a valid value for option calendarName");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue