Jasmine unit test for angular service In controller

可紊 提交于 2019-12-06 08:28:52

It's because you are not resolving promise. You will have to make change in spyOn.

 - spyOn(empService,"getInfo").and.callFake(function() {
            return {
                  then : function(success, error) {
                     success();
                }  
         } }

Now, it will go into the success callback and will try to call $scope.populateEmpData();

You're never resolving your promise. And you need to call $scope.$apply().

Why is this necessary? Because any promises made with the $q service to be resolved/rejected are processed upon each run of angular’s digest cycle. Conceptually, the call to .resolve changes the state of the promise and adds it to a queue. Each time angular’s digest cycle runs, any outstanding promises will be processed and removed from the queue. Unit Testing with $q Promises in AngularJS

Check it out above link it will help you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!