Hi César,

You need to call $digest before your promise will be resolved. Angular 
promises are async, so if you don't do a digest in between, your .then in 
the test will not be ran before your expect.

try:
describe('Testing promise', function() {
  var $scope = null;
  var myService = null;
  var cachedInstance = {
    name: 'John'
  }
  var rootScope = {}
  //you need to indicate your module in a test
  beforeEach(module('plunker'));


  beforeEach(inject(function(_myService_,$rootScope) {
    myService = _myService_;
    myService.cachedInstance = cachedInstance;
    $scope = $rootScope
  }));


  it('should return cached instance', function() {
    var resolvedInstance = {}
    myService.get().then(function(instance){
      resolvedInstance = instance;
    });
    $scope.$digest()
    expect(resolvedInstance).toBe(cachedInstance);
  });
});



Regards
Sander

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to