Last active
September 2, 2018 00:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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