测试功能不在控制器的范围内

时间:2014-01-03 18:33:24

标签: javascript angularjs angularjs-scope

我正在使用Karma测试跑者和Jasmine。我知道如何在示波器上测试功能。但是在这种情况下我该怎么做呢?

listing_app.controller('my_listing_products_list', ['$scope', '$modal',
        function ($scope, $modal) {
      this.someFn = function(a,b){
      //How do i test this function ?
       }

}]);

如何通过Jasmine获取此对象和控制器上下文?

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

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')
  });
})
相关问题