Last active
August 29, 2015 14:26
-
-
Save edysegura/16c3d92eafe649c3bc36 to your computer and use it in GitHub Desktop.
[angularjs] How to test a promise in AngularJS
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
//given | |
spyOn(YourService, 'yourMethod').and.callFake(function () { | |
var mockDeferred = $q.defer(); | |
mockDeferred.resolve(); | |
return mockDeferred.promise; | |
}); | |
//when | |
serviceOrScope.method(); | |
//and | |
$rootScope.$digest(); | |
//then | |
//assert your result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment