I've been trying to do a text of a function that handles errors in a way that, if it is a valid error, it is thrown, but if it is not, then nothing is thrown. The problem is that i cant seem to set the parameter while using:
expect(handleError).to.throw(Error);
The ideal would be to use:
expect(handleError(validError)).to.throw(Error);
Is there any way to achieve this functionality?
code of the function:
function handleError (err) {
if (err !== true) {
switch (err) {
case xxx:
...
}
throw "stop js execution";
else {}
}
And the code of the test (not working as intended):
it("should stop Javascript execution if the parameter isnt \"true\"", function() {
expect(handleError).to.be.a("function");
expect(handleError(true)).to.not.throw(Error);
expect(handleError("anything else")).to.throw(Error);
});