You're not passing your function to assert.throws()
the right way.
The assert.throws()
function expects a function as its first parameter. In your code, you are invoking iThrowError and passing its return value when calling assert.throws()
.
Basically, changing this:
assert.throws(iThrowError(), Error, "Error thrown");
to this:
assert.throws(iThrowError, Error, "Error thrown");
should solve your problem.
With args:
assert.throw(() => { iThrowError(args) }, Error);
or
assert.throw(function() { iThrowError(args) }, Error, /Error thrown/);