diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.@@hasInstance.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.@@hasInstance.js new file mode 100644 index 0000000000..d548a635fe --- /dev/null +++ b/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(); +}); diff --git a/Libraries/LibJS/Tests/custom-@@hasInstance.js b/Libraries/LibJS/Tests/custom-@@hasInstance.js new file mode 100644 index 0000000000..2540beaf68 --- /dev/null +++ b/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(); +});