-
-
Save auxcoder/72aa34670a489558948eb98e7802d14d to your computer and use it in GitHub Desktop.
Utility function for working with promises in angular tests.
This file contains hidden or 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