Created
October 21, 2012 01:14
-
-
Save adamyanalunas/3925377 to your computer and use it in GitHub Desktop.
jasmine.js matcher to test type of object
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
jasmine.Matchers.prototype.toBeTypeOf = function(expected) { | |
var actual, notText, objType; | |
actual = this.actual; | |
notText = this.isNot ? 'not ' : ''; | |
objType = actual ? Object.prototype.toString.call(actual) : ''; | |
this.message = function() { | |
return 'Expected ' + actual + notText + ' to be an array'; | |
} | |
return objType.toLowerCase() === '[object ' + expected.toLowerCase() + ']'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the idea.
Saves you the trouble of writing e.g.
expect(typeof(var)).toEqual('number')