I currently have two jest test cases the first one passes, but the second fails because its adding the sum of the previous case to that one
test('Subtotal to be 386.95 & VAT to be 54.173', () => {
cart = ["tshirt", "shoes", "jacket", "blouse", "pants"]
expect(calculateSubTotal(cart)).toBe(386.95);
expect(calculateVAT(cart)).toBe(54.173)
})
test('Subtotal to be 30.99 & VAT to be 4.388', () => {
cart = ["tshirt"]
expect(calculateSubTotal(cart)).toBe(30.99);
expect(calculateVAT(cart)).toBe(4.338)
});
expect(received).toBe(expected) // Object.is equality
Expected: 30.99
Received: 417.94
calculateSubTotal implementation:
cart.js
let products = {...} // products map by product name
let subTotal = 0 // line number 60
function calculateSubTotal(cart) {
// line number 75
for (i = 0; i < cart.length; i++) {
switch (cart[i]) {
case ("tshirt"):
subTotal += products.tshirt.price
break
case ("blouse"):
subTotal += products.blouse.price
break
// ... other product
}
}
subTotal = Number(subTotal.toFixed(2))
return subTotal
}
module.exports.calculateSubTotal = calculateSubTotal;
// another function
What do I need to do for jest to break out of the first test and not combine the test results?