I want to test the function B
to catch exception thrown from function A
with Mocha/Chai
.
function A() {
// 1. the third party API is called here
// some exception may be thrown from it
...
// 2. some exception could be thrown here
// caused by the logic in this function
}
function B() {
// To catch exception thrown by A()
try {
A();
} catch(err) {
console.error(err);
}
...
}
I want force A
to throw exception, while doing the test of B
. So I can make sure the function B
catch the exception from A
correctly.
After searching some posts:
Test for expected failure in Mocha
Testing JS exceptions with Mocha/Chai
I did not find the correct answer.
Is my question reasonable? if it is, how to do that test with Mocha/Chai
?