mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:08:10 +00:00
LibJS: Implement spec-compliant Object.prototype.toString
This commit is contained in:
parent
caa11503b1
commit
5ecd504f4e
4 changed files with 53 additions and 12 deletions
|
@ -16,9 +16,7 @@ describe("normal behavior", () => {
|
|||
});
|
||||
|
||||
test("number stringification differs from regular toString, for now", () => {
|
||||
expect([1, 2, 3].toLocaleString()).toBe(
|
||||
"[object NumberObject],[object NumberObject],[object NumberObject]"
|
||||
);
|
||||
expect([1, 2, 3].toLocaleString()).toBe("[object Number],[object Number],[object Number]");
|
||||
});
|
||||
|
||||
test("null and undefined result in empty strings", () => {
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
test("basic functionality", () => {
|
||||
test("length", () => {
|
||||
expect(Object.prototype.toString).toHaveLength(0);
|
||||
// FIXME: The tag is ObjectPrototype, but should be Object
|
||||
// expect(Object.prototype.toString()).toBe("[object Object]");
|
||||
expect({ foo: 1 }.toString()).toBe("[object Object]");
|
||||
expect([].toString()).toBe("");
|
||||
expect(Object.prototype.toString.call([])).toBe("[object Array]");
|
||||
});
|
||||
|
||||
test("result for various object types", () => {
|
||||
const oToString = o => Object.prototype.toString.call(o);
|
||||
|
||||
expect(oToString(undefined)).toBe("[object Undefined]");
|
||||
expect(oToString(null)).toBe("[object Null]");
|
||||
expect(oToString([])).toBe("[object Array]");
|
||||
expect(oToString(function () {})).toBe("[object Function]");
|
||||
expect(oToString(new Error())).toBe("[object Error]");
|
||||
expect(oToString(new Boolean())).toBe("[object Boolean]");
|
||||
expect(oToString(new Number())).toBe("[object Number]");
|
||||
expect(oToString(new Date())).toBe("[object Date]");
|
||||
expect(oToString(new RegExp())).toBe("[object RegExp]");
|
||||
expect(oToString({})).toBe("[object Object]");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue