I am currently working with a controller
var videoApp = angular.module('videoApp', ['videoAppFilters', 'ui.unique', 'angularUtils.directives.dirPagination']);
videoApp.controller('VideoCtrl', function ($scope, $http, $filter, cacheLoader, $rootScope) {
$scope.setPageSize = function (pageSize) {
$scope.pageSize = pageSize;
return $scope.pageSize;
};
$scope.addFavorite = function (data, key) {
localStorage.setItem(key, data);
$scope.videos = $filter('articleFilter')(data, $scope.allData);
return alert(key + " "+ data + " was added to your favorite list.");
};
$scope.addSelectedClass = function (event) {
if($(event.target).hasClass("selected") == true)
{
$(event.target).removeClass("selected");
} else {
$(".selected").removeClass("selected');
$(event.target).addClass("selected');
}
};
$scope.filterArticles = function (category) {
$scope.videos = $filter('articleFilter')(category, $scope.allData);
};
$scope.pageSize = 12;
cacheLoader.load('http://academy.tutoky.com/api/json.php', true, function () {
$scope.allData = $rootScope.allData;
$scope.videos = $rootScope.videos;
if(localStorage.getItem('category')) {
$scope.videos = $filter('articleFilter')(localStorage.getItem('category'), $scope.allData);
} else {
$scope.videos = data;
}
});
});
In addition, I have set up a test scenario
describe('Check if VideoListCtrl', function() {
beforeEach(module('videoApp'));
beforeEach(inject(function (_$controller_) {
$controller = _$controller_;
}));
beforeEach(inject(function ($rootScope) {
$scope = {};
controller = $controller('VideoCtrl', { $scope: $scope });
}));
it('exists', function() {
expect(controller).not.toBeNull();
});
it('set page size', function () {
expect($scope.setPageSize(12)).toEqual(12);
});
});
I am facing an issue while trying to test the functionality of my controller methods. Jasmine is throwing an error during the second test:
TypeError: undefined is not a function
The problem seems to be related to the line $scope.setPageSize(12). I followed the Angular docs tutorial which used scope methods in a similar way, but for some reason, it's not working in my case. Can anyone provide insight into why this might be happening?