1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:37:34 +00:00

LibJS: Start implementing Temporal.Calendar

Just like the previous Temporal.{Instant,TimeZone} commits, this patch
adds the Calendar object itself, its constructor and prototype
(currently empty), and two required abstract operations.
This commit is contained in:
Linus Groh 2021-07-14 21:01:12 +01:00
parent 48b66c7a68
commit a2f1d79765
12 changed files with 250 additions and 3 deletions

View file

@ -0,0 +1,38 @@
describe("errors", () => {
test("called without new", () => {
expect(() => {
Temporal.Calendar();
}).toThrowWithMessage(TypeError, "Temporal.Calendar constructor must be called with 'new'");
});
test("argument must be coercible to string", () => {
expect(() => {
new Temporal.Calendar({
toString() {
throw new Error();
},
});
}).toThrow(Error);
});
test("invalid calendar identifier", () => {
expect(() => {
new Temporal.Calendar("foo");
}).toThrowWithMessage(RangeError, "Invalid calendar identifier 'foo'");
});
});
describe("normal behavior", () => {
test("length is 1", () => {
expect(Temporal.Calendar).toHaveLength(1);
});
test("basic functionality", () => {
const calendar = new Temporal.Calendar("iso8601");
// FIXME: Enable this once Temporal.Calendar.prototype.id is implemented
// expect(calendar.id).toBe("iso8601");
expect(typeof calendar).toBe("object");
expect(calendar).toBeInstanceOf(Temporal.Calendar);
expect(Object.getPrototypeOf(calendar)).toBe(Temporal.Calendar.prototype);
});
});