Explorar o código

LibJS: Add Symbol.hasInstance tests

Matthew Olsson %!s(int64=5) %!d(string=hai) anos
pai
achega
6075defd55

+ 8 - 0
Libraries/LibJS/Tests/builtins/Function/Function.prototype.@@hasInstance.js

@@ -0,0 +1,8 @@
+test("basic functionality", () => {
+    expect(Function.prototype[Symbol.hasInstance]).toHaveLength(1);
+
+    function Foo() {}
+    const foo = new Foo();
+
+    expect(Function.prototype[Symbol.hasInstance].call(Foo, foo)).toBeTrue();
+});

+ 9 - 0
Libraries/LibJS/Tests/custom-@@hasInstance.js

@@ -0,0 +1,9 @@
+test("basic functionality", () => {
+    function Foo() {}
+    Foo[Symbol.hasInstance] = value => {
+        return value === 2;
+    };
+
+    expect(new Foo() instanceof Foo).toBeFalse();
+    expect(2 instanceof Foo).toBeTrue();
+});