Created
July 1, 2015 23:40
-
-
Save bbraithwaite/b129720c0ec834bd3827 to your computer and use it in GitHub Desktop.
Utility function for working with promises in angular tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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