I'm currently learning how to use Tape for unit testing. I've been able to verify that an error is thrown in my test. However, how can we verify that the message thrown with the Error is equal to an expected message?
Example unit test:
var test = require('tape'),
ExampleObject = require('/path/to/ExampleObject');
test("Pass invalid argument to function", function(assert){
assert.throws(function(){
new ExampleObject(undefined, "validParameter")
}, TypeError, "Should throw TypeError for firstParam");
assert.end();
});
ExampleObject:
function ExampleObject(param1, param2){
if(typeof param1 !== 'string') {
throw new TypeError('ExampleObject - typeof for param1 should be string');
}
if(typeof param2 !== 'string') {
throw new TypeError('ExampleObject - typeof for param2 should be string');
}
/*
/ do stuff
*/
};
Thanks in advance!
I opened an issue in the Github repo. At this time, .throws() doesn't support checking the Error type and message simultaneously.