Skip to content

Instantly share code, notes, and snippets.

@auxcoder
Forked from bbraithwaite/createPromiseSpy.js
Created August 6, 2016 16:12
Show Gist options
  • Save auxcoder/72aa34670a489558948eb98e7802d14d to your computer and use it in GitHub Desktop.
Save auxcoder/72aa34670a489558948eb98e7802d14d 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