Skip to content

Instantly share code, notes, and snippets.

@prantlf
Forked from adamyanalunas/jasmine.toBeTypeOf.js
Last active September 2, 2018 00:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prantlf/8631669 to your computer and use it in GitHub Desktop.
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
// 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