Testing for instanceof using Jasmine

Jasmine >=3.5.0

Jasmine provides the toBeInstanceOf matcher.

it("matches any value", () => {
  expect(3).toBeInstanceOf(Number);
});

Jasmine >2.3.0

To check if something is an instanceof [Object] Jasmine provides jasmine.any:

it("matches any value", function() {
  expect({}).toEqual(jasmine.any(Object));
  expect(12).toEqual(jasmine.any(Number));
});

Leave a Comment