Skip to content

Instantly share code, notes, and snippets.

@edysegura
Last active August 29, 2015 14:26
Show Gist options
  • Save edysegura/16c3d92eafe649c3bc36 to your computer and use it in GitHub Desktop.
Save edysegura/16c3d92eafe649c3bc36 to your computer and use it in GitHub Desktop.
[angularjs] How to test a promise in AngularJS
//given
spyOn(YourService, 'yourMethod').and.callFake(function () {
var mockDeferred = $q.defer();
mockDeferred.resolve();
return mockDeferred.promise;
});
//when
serviceOrScope.method();
//and
$rootScope.$digest();
//then
//assert your result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment