Reputation: 9738
How do i check whether a particular function is defined or not?
I am using following unit test, doesn't work.
controller
$scope.filterData = function () {
$scope.currentPage = "1";
$scope.displayData($scope.currentPage);
......
}
test
var ctrl, scope;
beforeEach(function () {
// load the module
module('myApp');
// inject Controller for testing
inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
ctrl = $controller('DataCtrl', { $scope: scope });
});
});
it('should have a filterData function to be defined', function () {
expect(scope.filterData()).toBeDefined();
});
Upvotes: 0
Views: 2534
Reputation: 4802
Remove the braces like this:
it('should have a filterData function to be defined', function () {
expect(scope.filterData).toBeDefined();
});
Since you dont wanna execute the function itself, but only check if its there.
Upvotes: 2