Description
Hello,
I read the code of the method t.doesNotThrow()
and I don't understand the purpose of the expected
parameter.
The documentation says :
expected
, if present, limits what should not be thrown, and must be aRegExp
orFunction
. TheRegExp
matches the string representation of the exception, as generated byerr.toString()
. For example, if you setexpected
to/user/
, the test will fail only if the string representation of the exception contains the worduser
. Any other exception will result in a passed test. TheFunction
is the exception thrown (e.g.Error
).
So, if my understanding is correct, the following tests should not fail :
const test = require("tape");
test('should not fail', (t) => {
t.doesNotThrow(
() => { throw new Error("Foo bar") },
TypeError,
"the callback does not throw a TypeError"
);
t.end();
});
test('should not fail', (t) => {
t.doesNotThrow(
() => { throw new Error("Foo bar") },
/baz/,
"the callback does not throw 'baz'"
);
t.end();
});
But the current behavior of t.doesNotThrow()
is to always fail if the callback throws an exception.
Should the method t.doesNotThrow()
be updated to match the documentation, or is my understanding of the documentation incorrect ?