Skip to content

Instantly share code, notes, and snippets.

@bbraithwaite
Created July 1, 2015 23:40
Show Gist options
  • Save bbraithwaite/b129720c0ec834bd3827 to your computer and use it in GitHub Desktop.
Save bbraithwaite/b129720c0ec834bd3827 to your computer and use it in GitHub Desktop.
Utility function for working with promises in angular tests.
var createPromiseSpy = function(obj, name, method, $q) {
var createdSpy = jasmine.createSpy(name, obj);
var returnObj = {};
var promise = {};
if (typeof(method) === 'string') {
var deferred = $q.defer();
spyOn(createdSpy, method).and.returnValue(deferred.promise);
promise[method] = deferred;
}
returnObj.instance = createdSpy;
returnObj.promise = promise;
return returnObj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment