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

LibJS: Implement Number.prototype.valueOf()

This commit is contained in:
Linus Groh 2021-06-06 06:56:08 +01:00
parent f09216ac42
commit adc3de4480
5 changed files with 51 additions and 13 deletions

View file

@ -75,7 +75,10 @@ describe("correct behavior", () => {
test("errors", () => {
test("must be called with numeric |this|", () => {
[true, [], {}, Symbol("foo"), "bar", 1n].forEach(value => {
expect(() => Number.prototype.toString.call(value)).toThrow(TypeError);
expect(() => Number.prototype.toString.call(value)).toThrowWithMessage(
TypeError,
"Number.prototype.toString() called with incompatible this target"
);
});
});

View file

@ -0,0 +1,21 @@
describe("correct behavior", () => {
test("length", () => {
expect(Number.prototype.valueOf).toHaveLength(0);
});
test("basic functionality", () => {
expect(new Number(42).valueOf()).toBe(42);
expect(Number.prototype.valueOf.call(42)).toBe(42);
});
});
test("errors", () => {
test("must be called with numeric |this|", () => {
[true, [], {}, Symbol("foo"), "bar", 1n].forEach(value => {
expect(() => Number.prototype.valueOf.call(value)).toThrowWithMessage(
TypeError,
"Number.prototype.valueOf() called with incompatible this target"
);
});
});
});