1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:57:35 +00:00

LibJS: Implement Date.prototype.setUTCMonth

This commit is contained in:
Timothy Flynn 2022-01-15 15:37:16 -05:00 committed by Andreas Kling
parent c71877b0a6
commit f2ffe3bf90
3 changed files with 80 additions and 1 deletions

View file

@ -0,0 +1,46 @@
describe("errors", () => {
test("called on non-Date object", () => {
expect(() => {
Date.prototype.setUTCMonth();
}).toThrowWithMessage(TypeError, "Not an object of type Date");
});
test("called with non-numeric parameters", () => {
expect(() => {
new Date().setUTCMonth(Symbol.hasInstance);
}).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
expect(() => {
new Date().setUTCMonth(1989, Symbol.hasInstance);
}).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
});
});
describe("correct behavior", () => {
const d = new Date(2000, 2, 1);
test("basic functionality", () => {
d.setUTCMonth(8);
expect(d.getUTCMonth()).toBe(8);
d.setUTCMonth(9, 15);
expect(d.getUTCMonth()).toBe(9);
expect(d.getUTCDate()).toBe(15);
d.setUTCMonth("");
expect(d.getUTCMonth()).toBe(0);
d.setUTCMonth("a");
expect(d.getUTCMonth()).toBe(NaN);
});
test("NaN", () => {
d.setUTCMonth(NaN);
expect(d.getUTCMonth()).toBeNaN();
});
test("time clip", () => {
d.setUTCMonth(8.65e15);
expect(d.getUTCMonth()).toBeNaN();
});
});