Skip to content

Instantly share code, notes, and snippets.

@heat
Created September 4, 2012 19:45
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save heat/3625555 to your computer and use it in GitHub Desktop.
Save heat/3625555 to your computer and use it in GitHub Desktop.
Jasmine Matcher instanceof
beforeEach(function() {
this.addMatchers({
toBeInstanceOf: function(expectedInstance) {
var actual = this.actual;
var notText = this.isNot ? " not" : "";
this.message = function() {
return "Expected " + actual.constructor.name + notText + " is instance of " + expectedInstance.name;
};
return actual instanceof expectedInstance;
}
});
});
@luchillo17
Copy link

I tough you could set up the output to the expectation as the second arg to .toEqual(), .toBeTruthy() and most expectation comparison does accept some kind of configuration argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment