mercredi 31 août 2016

angular test case $scope.$apply

Why is it mandatory to execute $scope.$apply() in a test case for async process to finish.

say i have a service

angular.service("a",function($q){
    return {
        getValue: function(){
            return $q.resolve(someObj)
        }
    }
})

And in my test

it("test this",function(done){
    a.getValue()
    .then(function(data){
        expect(data).toEqual(data)
        done();
    })
    $scope.$apply();
})

Aucun commentaire:

Enregistrer un commentaire