Call selectRow on ng grid in jasmine unit test

I have an angular controller jasmine test using ng mesh. I want to call selectRow(1, true);angular in the grid, but when I do this, I get an errorTypeError: Object #<Object> has no method 'selectRow'

I have an angular controller that sets up an ng grid as follows:

    $scope.myGridOptions = {
            data : 'myData',
            multiSelect: false,
            selectedItems: $scope.mySelectedRow,
            afterSelectionChange: function(data) {;
                if($scope.mySelectedRow === undefined){
                    //do somthing
                }else{
                    //do somthing else
                }
            }
        };

Then I have jasmine unit test, where I create an instance of my controller using the input function, setting the object scopeto equal controllers $scope. Then I have a bunch of tests that are not related to the grid, and they all run and pass fine.

However, I want to test the logic of the select handler, so I test it as follows:

    it('selecting a row in the table does stuff.', function() {
      //controller created in before each
              rootScope.$digest();//needed to get the controller to initialize
      scope.myGridOptions.$selectRow(1, true);
      expect(scope.resultOfDoingSomthing).toBe("done");
  });

, . maven jasime:bdd , . , , angular -jasmine, . javascript ng-grid. module("ngGrid") beforeEach . beforeEach(module("myMod",['ng-grid'])); $injector.

+3
1

. , , afterSelectionChange , , selectRow. , :

    afterSelectionChange: function(data) {;
            if($scope.mySelectedRow === undefined){
                //do somthing
            }else{
                //do somthing else
            }
        }

    afterSelectionChange: function(rowItem, event) {;
            if(rowItem.entity === undefined){
                //do somthing
            }else{
                //do somthing with row rowItem
            }
        }

, , , .

+2

All Articles