title: Jasmine Test Consecutive Promise Calls
body: <p>I have the following test that does the following:</p>
  
  <ol>
  <li>Makes a mocked out service call that returns a promise which resolves to some currency codes.</li>
  <li>Assert that the currency codes that are set on the controller's scope match what was returned by the mocked out service.</li>
  <li>Makes a second mocked out service call that results in an error.</li>
  <li>Assert that the currency codes set on the controller's scope are null.</li>
  </ol>
  
  <p>The assertion at step 2 fails because the currency codes are null.  It seems like I can't sequence the promises in my test.  The code is below:</p>
  
  <pre><code>    beforeEach(inject(function($rootScope, $controller, $log, $q) {
          //.....
          spyOn(clientMoneyService, findCurrencyCodes').andReturn(deferral.promise);
  }));
  
  it('should clear currency codes on error', inject(function() {
      scope.findCurrencyCodes();
      // first call returns currencies
      deferral.resolve(response);
      var response = {
          data: ['AUD', 'CAD']
      };
      scope.$apply();
      expect(scope.currencyCodes).toEqual(['AUD', 'CAD']);
  
      // second call errors out
      deferral.reject();
      scope.findCurrencyCodes();
      scope.$apply();
      expect(scope.currencyCodes).toBeNull();
  }));
  </code></pre>
  
  <p>Is there a way to sequence my promises so that on the first call I get a list of currency codes and the second call I get an error?</p>