Testing the web shop
Let's continue to add some tests for our web shop. The first thing we should ask ourselves is which files we should test in the first place. For now, the most obvious file is the shopping cart module. When we look at the shopping cart module, it seems like it is pretty difficult to test this file. An obvious test would be to add a product and check whether the price is correctly updated. However, the Line
object is private to the controller and the controller $scope
represents the entire cart. We have two options here: either we find out if and how we can get access to the $scope
object in our unit tests or we create an additional file that has the shopping cart object and that we can reuse in our controller (or even non-Angular.js projects). You can already see that we are forced to think about our code in a certain way, because we need to use our code in the application where we really need it. Also, in our unit tests, we need to write more generic code than we might...