Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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