diff --git a/src/logic/calculate.test.js b/src/logic/calculate.test.js index 1388ec6ce..939e83331 100644 --- a/src/logic/calculate.test.js +++ b/src/logic/calculate.test.js @@ -154,4 +154,20 @@ describe("calculate", function() { test(["2", "x", "2", "%"], { total: "0.04", }); + + //Test that pressing the multiplication or division sign multiple times should not affect the current computation + test(["2", "x", "x"], { + total: "2", + operation: "x" + }); + + test(["2", "÷", "÷"], { + total: "2", + operation: "÷" + }); + + test(["2", "÷", "x", "+", "-", "x"], { + total: "2", + operation: 'x' + }); }); diff --git a/src/logic/operate.js b/src/logic/operate.js index b1b1ed928..0274e3a74 100644 --- a/src/logic/operate.js +++ b/src/logic/operate.js @@ -2,7 +2,7 @@ import Big from "big.js"; export default function operate(numberOne, numberTwo, operation) { const one = Big(numberOne || "0"); - const two = Big(numberTwo || "0"); + const two = Big(numberTwo || (operation === "÷" || operation === 'x' ? "1": "0")); //If dividing or multiplying, then 1 maintains current value in cases of null if (operation === "+") { return one.plus(two).toString(); }