Skip to content

Instantly share code, notes, and snippets.

@DorkForce
Created February 5, 2016 17:42
Show Gist options
  • Save DorkForce/763ad715b5d5ee904995 to your computer and use it in GitHub Desktop.
Save DorkForce/763ad715b5d5ee904995 to your computer and use it in GitHub Desktop.
Mock a service to return a promise
// from http://stackoverflow.com/questions/23705051/how-do-i-mock-a-service-that-returns-promise-in-angularjs-jasmine-unit-test
beforeEach(inject( function(_myService_, $q){
myService = _myService_;
myOtherServiceMock.makeRemoteCallReturningPromise = function() {
var deferred = $q.defer();
deferred.resolve('Remote call result');
return deferred.promise;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment