测试功能不在控制器的范围内 [英] Testing functions not on the scope in the controller
本文介绍了测试功能不在控制器的范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Karma 测试运行程序和 Jasmine.我知道如何在作用域上测试函数.但在这种情况下,我该怎么做?
I am using Karma test runner and Jasmine. I know how to test functions on the scope.But in case of a situation like this how do I go about it ?
listing_app.controller('my_listing_products_list', ['$scope', '$modal',
function ($scope, $modal) {
this.someFn = function(a,b){
//How do i test this function ?
}
}]);
如何通过 Jasmine 获取 this 对象和控制器上下文?
How do I get hold of the this object and the controller context through Jasmine ?
推荐答案
尝试以下操作:
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')
});
})
这篇关于测试功能不在控制器的范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文