We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The test as-is didn't cover faulty operator handling, so I came up with
// calculator.test.js // Division ... // Error case: Invalid operator expect(() => calculator(num1, num2, "//")).toThrow("Invalid operator");
Adding the error throwing handling naturally requires the main file to throw an error in this case. I used the default for that:
function calculator(num1, num2, operator) { switch (operator) { case "+": return num1 + num2; case "-": return num1 - num2; case "*": return num1 * num2; case "/": return num1 / num2; default: throw new Error('Invalid operator'); } }
This way, anything other than the operators throws an error. You're welcome to use it, if you choose.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The test as-is didn't cover faulty operator handling, so I came up with
Adding the error throwing handling naturally requires the main file to throw an error in this case. I used the default for that:
This way, anything other than the operators throws an error. You're welcome to use it, if you choose.
The text was updated successfully, but these errors were encountered: