title: How do you mock a service in AngularJS when unit testing with jasmine?
body: <p>Let's say I have a service <code>shop</code> that depends on two stateful services <code>schedule</code> and <code>warehouse</code>. How do I inject different versions of <code>schedule</code> and <code>warehose</code> into <code>shop</code> for unit testing?</p>
  
  <p>Here's my service:</p>
  
  <pre><code>angular.module('myModule').service('shop', function(schedule, warehouse) {
      return {
          canSellSweets : function(numRequiredSweets){
               return schedule.isShopOpen()
                   &amp;&amp; (warehouse.numAvailableSweets() &gt; numRequiredSweets);
          }
      }
  });
  </code></pre>
  
  <p>Here are my mocks:</p>
  
  <pre><code>var mockSchedule = {
      isShopOpen : function() {return true}
  }
  var mockWarehouse = {
      numAvailableSweets: function(){return 10};
  }
  </code></pre>
  
  <p>Here are my tests:</p>
  
  <pre><code>expect(shop.canSellSweets(5)).toBe(true);
  expect(shop.canSellSweets(20)).toBe(false);
  </code></pre>