1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:47:36 +00:00

LibJS: Implement Date.prototype.setUTCMilliseconds

This commit is contained in:
Timothy Flynn 2022-01-15 15:44:55 -05:00 committed by Andreas Kling
parent 2f202e8ef4
commit 6998c0a796
3 changed files with 72 additions and 4 deletions

View file

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