Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updation required in Test Case for Calculator.js - Hard Problem in 01-js #14

Open
ankit-95 opened this issue Jun 12, 2023 · 1 comment

Comments

@ankit-95
Copy link

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;
  }
@ankit-95 ankit-95 changed the title Update required in Test Case for Calculator.js - Hard Problem in 01-js Updation required in Test Case for Calculator.js - Hard Problem in 01-js Jun 12, 2023
@AsbarK
Copy link

AsbarK commented Jun 14, 2023

bro the test case is for calculate() method not divide
you add this in calculate()

if (!isFinite(this.result)) {
throw Error();
}
the test case will pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants