title: jasmine test function that returns a promise
body: <p>I have the following function implementation</p>
  
  <pre><code>function getRepo(url) {
      var repos = {};
  
      if (repos.hasOwnProperty(url)) {
          return repos[url];
      }
  
      return $.get(url)
          .then(repoRetrieved)
          .fail(failureHandler);
  
      function repoRetrieved(data) {
  
          return repos[url] = data;
      }
  
      function failureHandler(err, xhr) {
          throw new Error(xhr.responseText);
      }
  }
  </code></pre>
  
  <p>And i wrote the following tests:</p>
  
  <pre><code>describe('"getRepo" method', function() {
      var getDeffered;
      var $;
  
       beforeEach(function() {
           getDeffered = Q.defer();
           $ = jasmine.createSpyObj('$', ['get']);
           $.get.and.returnValue(getDeffered.promise);
       });
  
       it('should return a promise', function(){
           expect(getRepo('someURL')).toEqual(getDeffered.promise);
       });
  
  });
  </code></pre>
  
  <p>And this test fails. I think because i call the then method.</p>
  
  <p>It does not fail if function implementation is:</p>
  
  <pre><code>function getRepo(url) {
      return $.get(url);
  }
  </code></pre>
  
  <p>this is the message jasmine throws when using Q.defer()</p>
  
  <pre><code>Expected { promiseDispatch : Function, valueOf : Function, inspect : Function }
  to equal { promiseDispatch : Function, valueOf : Function, inspect : Function }.
  </code></pre>
  
  <p>And this is the message if i use jQuery Deferred:</p>
  
  <pre><code>Expected { state : Function, always : Function, then : Function, promise : Function, pipe : Function, done : Function, fail : Function, progress : Function } 
  to equal { state : Function, always : Function, then : Function, promise : Function, pipe : Function, done : Function, fail : Function, progress : Function }.
  </code></pre>
  
  <p>jQuery Deferred test implementation:</p>
  
  <pre><code>describe('"getRepo" method', function() {
      var getDeffered;
      var $;
  
      beforeEach(function() {
          getDeffered = real$.Deferred();
          $ = jasmine.createSpyObj('$', ['get']);
          $.get.and.returnValue(getDeffered.promise());
      });
  
      it('should return a promise', function(){
          expect(getRepo('someURL')).toEqual(getDeffered.promise());
      });
  
  });
  </code></pre>