Here's the problem, I'm trying to do an automatic test to see if addToCart() works correctly.
addToCart();
if(Kiosk.GetCart().toString() !== emptyCartString){
setTestResults('addToCart', 'Passed');
}
else{
setTestResults('addToCart', 'Failed');
}
I'm adding a product to an empty cart, then I want to check to see if the cart is still empty, if something is there then addToCart() worked and the test has passed. If the cart is still empty after the addToCart() call then the test should fail.
What is happening is that the addToCart() method takes a while to execute and in the meantime the 'if' statement fires and checks the cart before addToCart() has a chance to return, and thus the test always fails.
Callbacks are the answer, correct? But what's the best way to implement them here?