I do prefer the more readable/intuitive (in my opinion) use with the instanceof operator.
class Parent {}
class Child extends Parent {}
let c = new Child();
expect(c instanceof Child).toBeTruthy();
expect(c instanceof Parent).toBeTruthy();
For the sake of completeness you can also use the prototype constructor
property in some cases.
expect(my_var_1.constructor).toBe(Array);
expect(my_var_2.constructor).toBe(Object);
expect(my_var_3.constructor).toBe(Error);
// ...
BEWARE that this won't work if you need to check whether an object inherited from another or not.
class Parent {}
class Child extends Parent {}
let c = new Child();
console.log(c.constructor === Child); // prints "true"
console.log(c.constructor === Parent); // prints "false"
If you need inheritance support definitely use the instanceof
operator or the jasmine.any() function like Roger suggested.
Object.prototype.constructor reference.