Test functions are outside the scope of the controller
I am using Karma test runner and Jasmine. I know how to test functions in a scope. But in such a situation, how to do it?
listing_app.controller('my_listing_products_list', ['$scope', '$modal',
function ($scope, $modal) {
this.someFn = function(a,b){
//How do i test this function ?
}
}]);
How do I access this object and controller context through Jasmine?
0
source to share
1 answer
Try the following:
describe('my_listing_products_list controller', function(){
beforeEach(inject(function($controller, $rootScope){
scope = $rootScope.$new();
ctrl = $controller("my_listing_products_list", {$scope: scope});
}));
it('should exist', function($controller){
expect(ctrl.someFn()).toBe('whatever the function returns')
});
})
+1
source to share