instanceof-basic.js 750 B

123456789101112131415161718192021222324252627282930313233343536
  1. test("basic functionality", () => {
  2. function Foo() {
  3. this.x = 123;
  4. }
  5. const foo = new Foo();
  6. expect(foo instanceof Foo).toBeTrue();
  7. });
  8. test("derived ES5 classes", () => {
  9. function Base() {
  10. this.is_base = true;
  11. }
  12. function Derived() {
  13. this.is_derived = true;
  14. }
  15. Object.setPrototypeOf(Derived.prototype, Base.prototype);
  16. const d = new Derived();
  17. expect(d instanceof Derived).toBeTrue();
  18. expect(d instanceof Base).toBeTrue();
  19. });
  20. test("issue #3930, instanceof on arrow function", () => {
  21. function f() {}
  22. const a = () => {};
  23. expect(() => {
  24. f instanceof a;
  25. }).toThrow(TypeError);
  26. expect(() => {
  27. a instanceof a;
  28. }).toThrow(TypeError);
  29. });