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();
});
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.