Forked from adamyanalunas/jasmine.toBeTypeOf.js
Last active
September 2, 2018 00:13
-
-
Save prantlf/8631669 to your computer and use it in GitHub Desktop.
A Jasmine matcher checking if the actual object is of the expected type
This file contains hidden or 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 of the expected type; | |
// the string `expected` is handled case-insensitively. | |
// | |
// Example: | |
// expects(123).toBeTypeOf("Number"); | |
jasmine.Matchers.prototype.toBeTypeOf = function(expected) { | |
var actual = this.actual, | |
notText = this.isNot ? ' not' : '', | |
objType = actual ? Object.prototype.toString.call(actual) : ''; | |
this.message = function() { | |
return 'Expected ' + actual + notText + ' to be the type of ' + expected; | |
} | |
return objType.toLowerCase() === '[object ' + expected.toLowerCase() + ']'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment