Before :
test("calculate division by zero", () => {
expect(() => calc.calculate("10 / 0")).toThrow(Error);
});
After :
test("calculate division by zero", () => {
expect(() => calc.calculate("10 / 0").value()).toThrow(Error);
});
I would recommend this changes as current code is not working even if error is thrown while checking for division by zero. i.e,
Below code is correct in my view, but still test case is failing.
divide(num) {
if (num === 0) throw new Error("NaN");
this.result /= num;
}