Question

The script works, but not if I test it.

Jasmine:

describe("myApp", function(){

        beforeEach(module("mymod"));

        describe("maincontroller", function(){

            var scope;
            var ctrl;
            var compile;
            var html;
            beforeEach(inject(function($rootScope, $controller, $compile){
                scope = $rootScope.$new();
                ctrl = $controller("maincontroller", {$scope:scope});

                compile = $compile;

                html = angular.element('<ul id="listONE"><li class="{{person.isSel}}" ng-repeat="person in people" ng-click="selPersonToChange($index)">{{person.name +" - "+ person.city}}</li></ul>');
                compile(html)(scope);
                scope.$digest();    

            }));

            it("Is selPersonToChange() working?", function(){
                expect(scope.selPersonToChange(ind)).toEqual(true);
            });
});
Was it helpful?

Solution

You haven't defined 'ind' anywhere in that JavaScript file. The ng-click should work as $index is defined in the ng-repeat. But your test has declaration of 'ind'.

OTHER TIPS

You aren't giving selPersonToChange any index to change, it should be

it("Is selPersonToChange() working?", function(){
    var ind = 0;
    scope.selPersonToChange(ind);
    // scope.$digest(); // only needed if it needs to reflect on your DOM
    expect(scope.people[ind].isSel).toEqual(true);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top