Error is thrown but Jest's `toThrow()` does not capture the error
expect(fn).toThrow()
expects a function fn
that, when called, throws an exception.
However you are calling CheckFunctionExistenceByStr
immediatelly, which causes the function to throw before running the assert.
Replace
test(`
expect(CheckFunctionExistenceByStr(
'any string', 'FunctionThatDoesNotExistsInString'
)).toThrow();
`, () => {
expect(CheckFunctionExistenceByStr(
'any string', 'FunctionThatDoesNotExistsInString'
)).toThrow();
}
);
with
test(`
expect(() => {
CheckFunctionExistenceByStr(
'any string', 'FunctionThatDoesNotExistsInString'
)
}).toThrow();
`, () => {
expect(() => {
CheckFunctionExistenceByStr(
'any string', 'FunctionThatDoesNotExistsInString'
)
}).toThrow();
}
);