1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 10:17:35 +00:00
serenity/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.js
Linus Groh a2f1d79765 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.
2021-07-14 23:50:03 +01:00

38 lines
1.2 KiB
JavaScript

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);
});
});