mardi 10 avril 2018

Karma Jasmine testing for $route.reload on a $timeout failing

Added a timeout to reload the page in the controller after a certain amount of time, however now all the karma tests are failing.

Controller code:

function mainController($route, $scope, $timeout) {
    $scope.toggle = false;        

    $scope.value = function() {
        if($scope.value) {
           $scope.toggle = true;
        } else {
           $scope.toggle = false;
        }
    }

    $timeout($route.reload, 10000);
}

Tests:

describe('mainController:', function() {

    describe('test mainController', function () {
       beforeEach(inject(function ($injector) { 
           this.$scope = $injector.get('$rootScope').$new();
           this.$route = $injector.get('$route');
           this.$timeout = $injector.get('$timeout');
       })); 
    });

    describe('test value', function () { 
        it('value is valid', function () {
            this.$scope.value = undefined;
            this.$controller('mainController', {$route: this.$route, $scope: this.$scope, $timeout: this.$timeout});

            expect(this.$scope.value).toBe(false);                

        });
    });
});

Error: mainController: test value, value is valid FAILED Error: [$injector:unpr] Unkown provider: $routeProvider <- $route TypeError: Cannot read property 'reload' of defined

Aucun commentaire:

Enregistrer un commentaire