diff options
author | Linus Groh <mail@linusgroh.de> | 2021-08-16 18:04:58 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-08-16 20:40:21 +0100 |
commit | 31f65b8c500aa92a082653deb74fbfa11637a696 (patch) | |
tree | 033d11fc4b9863c1f86ed6a83ea03f687ba12af1 /Userland/Libraries/LibJS/Tests/builtins/Temporal | |
parent | 68d07320cf0df9603fba26e1c19e533d29772bd2 (diff) | |
download | serenity-31f65b8c500aa92a082653deb74fbfa11637a696.zip |
LibJS: Implement Temporal.Calendar.prototype.monthDayFromFields()
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/builtins/Temporal')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.monthDayFromFields.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.monthDayFromFields.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.monthDayFromFields.js new file mode 100644 index 0000000000..6d55420c28 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.monthDayFromFields.js @@ -0,0 +1,60 @@ +describe("correct behavior", () => { + test("length is 2", () => { + expect(Temporal.Calendar.prototype.monthDayFromFields).toHaveLength(2); + }); + + test("basic functionality", () => { + const calendar = new Temporal.Calendar("iso8601"); + const plainMonthDay = calendar.monthDayFromFields({ year: 2021, month: 7, day: 6 }); + expect(plainMonthDay.calendar).toBe(calendar); + expect(plainMonthDay.monthCode).toBe("M07"); + expect(plainMonthDay.day).toBe(6); + + const fields = plainMonthDay.getISOFields(); + expect(fields.isoYear).toBe(1972); // No, this isn't a mistake + }); + + test("with monthCode", () => { + const calendar = new Temporal.Calendar("iso8601"); + const plainMonthDay = calendar.monthDayFromFields({ monthCode: "M07", day: 6 }); + expect(plainMonthDay.calendar).toBe(calendar); + expect(plainMonthDay.monthCode).toBe("M07"); + expect(plainMonthDay.day).toBe(6); + + const fields = plainMonthDay.getISOFields(); + expect(fields.isoYear).toBe(1972); + }); +}); + +describe("errors", () => { + test("first argument must be an object", () => { + const calendar = new Temporal.Calendar("iso8601"); + expect(() => { + calendar.monthDayFromFields(42); + }).toThrowWithMessage(TypeError, "42 is not an object"); + }); + + test("month or monthCode field is required", () => { + const calendar = new Temporal.Calendar("iso8601"); + expect(() => { + calendar.monthDayFromFields({ year: 2021 }); + }).toThrowWithMessage(TypeError, "Required property month is missing or undefined"); + }); + + test("day field is required", () => { + const calendar = new Temporal.Calendar("iso8601"); + expect(() => { + calendar.monthDayFromFields({ year: 2021, month: 7 }); + }).toThrowWithMessage(TypeError, "Required property day is missing or undefined"); + }); + + test("monthCode or year field is required when month is given", () => { + const calendar = new Temporal.Calendar("iso8601"); + expect(() => { + calendar.monthDayFromFields({ month: 7, day: 6 }); + }).toThrowWithMessage( + TypeError, + "Required property monthCode or year is missing or undefined" + ); + }); +}); |