diff options
Diffstat (limited to 'Libraries/LibJS/Tests')
6 files changed, 45 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.@@toStringTag.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.@@toStringTag.js new file mode 100644 index 0000000000..44812778a4 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.@@toStringTag.js @@ -0,0 +1,3 @@ +test("basic functionality", () => { + expect(BigInt.prototype[Symbol.toStringTag]).toBe("BigInt"); +}); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.@@toStringTag.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.@@toStringTag.js new file mode 100644 index 0000000000..5a1e51f7c6 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.@@toStringTag.js @@ -0,0 +1,4 @@ +test("basic functionality", () => { + expect(JSON[Symbol.toStringTag]).toBe("JSON"); + expect(JSON.toString()).toBe("[object JSON]"); +}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.@@toStringTag.js b/Libraries/LibJS/Tests/builtins/Math/Math.@@toStringTag.js new file mode 100644 index 0000000000..69815a1499 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.@@toStringTag.js @@ -0,0 +1,4 @@ +test("basic functionality", () => { + expect(Math[Symbol.toStringTag]).toBe("Math"); + expect(Math.toString()).toBe("[object Math]"); +}); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.@@toStringTag.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.@@toStringTag.js new file mode 100644 index 0000000000..c73e637fc4 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.@@toStringTag.js @@ -0,0 +1,3 @@ +test("basic functionality", () => { + expect(Symbol.prototype[Symbol.toStringTag]).toBe("Symbol"); +}); diff --git a/Libraries/LibJS/Tests/custom-@@toStringTag.js b/Libraries/LibJS/Tests/custom-@@toStringTag.js new file mode 100644 index 0000000000..e297961e55 --- /dev/null +++ b/Libraries/LibJS/Tests/custom-@@toStringTag.js @@ -0,0 +1,26 @@ +test("inside objects", () => { + const o = { + [Symbol.toStringTag]: "hello friends", + }; + + expect(o.toString()).toBe("[object hello friends]"); +}); + +test("inside classes", () => { + class A { + constructor() { + this[Symbol.toStringTag] = "hello friends"; + } + } + + const a = new A(); + expect(a.toString()).toBe("[object hello friends]"); +}); + +test("non-string values are ignored", () => { + const o = { + [Symbol.toStringTag]: [1, 2, 3], + }; + + expect(o.toString()).toBe("[object Object]"); +}); diff --git a/Libraries/LibJS/Tests/iterators/array-iterator.js b/Libraries/LibJS/Tests/iterators/array-iterator.js index 117030ebdf..8f02845ebe 100644 --- a/Libraries/LibJS/Tests/iterators/array-iterator.js +++ b/Libraries/LibJS/Tests/iterators/array-iterator.js @@ -2,6 +2,11 @@ test("length", () => { expect(Array.prototype[Symbol.iterator].length).toBe(0); }); +test("@@toStringTag", () => { + expect([].values()[Symbol.toStringTag]).toBe("Array Iterator"); + expect([].values().toString()).toBe("[object Array Iterator]"); +}); + test("same function as Array.prototype.values", () => { expect(Array.prototype[Symbol.iterator]).toBe(Array.prototype.values); }); |