diff options
Diffstat (limited to 'Libraries/LibJS/Tests/classes/class-advanced-extends.js')
-rw-r--r-- | Libraries/LibJS/Tests/classes/class-advanced-extends.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/classes/class-advanced-extends.js b/Libraries/LibJS/Tests/classes/class-advanced-extends.js new file mode 100644 index 0000000000..749f65003c --- /dev/null +++ b/Libraries/LibJS/Tests/classes/class-advanced-extends.js @@ -0,0 +1,35 @@ +test("extending function", () => { + class A extends function () { + this.foo = 10; + } {} + + expect(new A().foo).toBe(10); +}); + +test("extending null", () => { + class A extends null {} + + expect(Object.getPrototypeOf(A.prototype)).toBeNull(); + + expect(() => { + new A(); + }).toThrowWithMessage(ReferenceError, "|this| has not been initialized"); +}); + +test("extending String", () => { + class MyString extends String {} + + const ms = new MyString("abc"); + expect(ms).toBeInstanceOf(MyString); + expect(ms).toBeInstanceOf(String); + expect(ms.charAt(1)).toBe("b"); + + class MyString2 extends MyString { + charAt(i) { + return `#${super.charAt(i)}`; + } + } + + const ms2 = new MyString2("abc"); + expect(ms2.charAt(1)).toBe("#b"); +}); |