diff options
author | Linus Groh <mail@linusgroh.de> | 2021-08-19 08:39:34 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-08-20 18:12:15 +0100 |
commit | ea44f33d5b1ef9f8972b469184cd5e879da661cc (patch) | |
tree | 1d0f5501197a08918e3f4b42f7848580a37d2957 /Userland/Libraries/LibJS/Tests/builtins/Temporal | |
parent | c1c8d7861c42b63de7c757bd19bbb9bed81d75f1 (diff) | |
download | serenity-ea44f33d5b1ef9f8972b469184cd5e879da661cc.zip |
LibJS: Implement Temporal.PlainMonthDay.prototype.toString()
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/builtins/Temporal')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.toString.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.toString.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.toString.js new file mode 100644 index 0000000000..df09430402 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.toString.js @@ -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"); + }); +}); |