sorting feature in ngTable using Jasmine Testing

纵饮孤独 提交于 2019-12-04 17:47:46

You could:

Declare getData function on controller's $scope, thus making it available in your test:

$scope.tableParams = new ngTableParams({
        sorting: {
            name: 'asc'     
        }
    }, {
        getData: $scope.getData
    });

$scope.getData = function($defer, params) {
            $scope.myValues = $filter('orderBy')($scope.myValues, params.orderBy());
            $defer.resolve($scope.myValues);
        }

Inject $q in beforeEach().

Create a promise object using $q.

Assign some $scope.myValues for your unit test.

Declare a variable containing your expected result - that is your sorted $scope.myValues array. Then:

promise.then(function(result){
    expect(result).toEqual(expectedResult);
}
$scope.getData(deferred , $scope.tableParams);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!