LibJS: Add Symbol.hasInstance tests

This commit is contained in:
Matthew Olsson 2020-07-11 15:37:35 -07:00 committed by Andreas Kling
parent b0296735a5
commit 6075defd55
Notes: sideshowbarker 2024-07-19 04:49:44 +09:00
2 changed files with 17 additions and 0 deletions

View file

@ -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();
});

View file

@ -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();
});