mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:17:36 +00:00
LibJS: Implement Temporal.ZonedDateTime.prototype.withCalendar
This commit is contained in:
parent
58bb73b60f
commit
b8db0ddc70
3 changed files with 59 additions and 0 deletions
|
@ -0,0 +1,43 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 1", () => {
|
||||
expect(Temporal.ZonedDateTime.prototype.withCalendar).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
const object = {};
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1n, {}, object);
|
||||
expect(zonedDateTime.calendar).toBe(object);
|
||||
|
||||
const calendar = new Temporal.Calendar("iso8601");
|
||||
const withCalendarZonedDateTime = zonedDateTime.withCalendar(calendar);
|
||||
expect(withCalendarZonedDateTime.calendar).toBe(calendar);
|
||||
});
|
||||
|
||||
test("from calendar string", () => {
|
||||
const object = {};
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1n, {}, object);
|
||||
expect(zonedDateTime.calendar).toBe(object);
|
||||
|
||||
const withCalendarZonedDateTime = zonedDateTime.withCalendar("iso8601");
|
||||
expect(withCalendarZonedDateTime.calendar).toBeInstanceOf(Temporal.Calendar);
|
||||
expect(withCalendarZonedDateTime.calendar.id).toBe("iso8601");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Temporal.ZonedDateTime.prototype.withCalendar.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
|
||||
// FIXME: Enable this when calendar string parsing is implemented.
|
||||
test.skip("from invalid calendar string", () => {
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1n, {}, {});
|
||||
|
||||
// FIXME: Use "toThrowWithMessage" once this has an error message.
|
||||
expect(() => {
|
||||
zonedDateTime.withCalendar("iso8602foobar");
|
||||
}).toThrow(RangeError);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue