Skip to content

Instantly share code, notes, and snippets.

@79yuuki
Created March 14, 2013 03:30
Show Gist options
  • Save 79yuuki/5158593 to your computer and use it in GitHub Desktop.
Save 79yuuki/5158593 to your computer and use it in GitHub Desktop.
expect.js test tips
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