Created
March 14, 2013 03:30
-
-
Save 79yuuki/5158593 to your computer and use it in GitHub Desktop.
expect.js test tips
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
function targetMethod(param) { | |
if(param === null || param === undefined) { | |
throw new Error('param is empty.'); | |
} | |
if(typeof param !== 'string') { | |
throw new Error('param must be a Number.'); | |
} | |
console.log(param); | |
} | |
// closure | |
var result1 = function() { | |
var _badParam = null; | |
targetMethod(_badParam); | |
}; | |
var result2 = function() { | |
var _badParam = 'string'; | |
targetMethod(_badParam); | |
} | |
// throwError | |
expect(result1).to.throwError(); | |
// Check the error message using a regex. | |
expect(result1).to.throwError(/param is empty/); | |
expect(result2).to.throwError(/param must be a Number./); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment