Skip to content

Instantly share code, notes, and snippets.

@prantlf
Last active September 2, 2018 00:12
Show Gist options
  • Save prantlf/8631877 to your computer and use it in GitHub Desktop.
Save prantlf/8631877 to your computer and use it in GitHub Desktop.
A Jasmine matcher checking if the actual object is an instance of the expected type
// Checks if the actual object is an instance of the expected type;
// the functional object `expected` can be any ancestor prototype.
//
// Example:
// expects(new Backbone.Model()).toBeInstanceOf(Backbone.Model);
jasmine.Matchers.prototype.toBeInstanceOf = function(expected) {
var actual = this.actual,
notText = this.isNot ? ' not' : '';
this.message = function() {
return 'Expected ' + actual + notText + ' to be an instance of ' + expected;
}
return actual instanceof expected;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment