2016-06-09 50 views
0
'use strict'; 
define([], function() { 

function myController($scope) { 
    //Do something... 
    }; 
} 

myController.inject = ['$scope']; 

return myController; 

});无法调用Jasmine中的控制器的功能

对于上述控制器,我无法调用myController。请参阅下面的代码(茉莉花)。

describe('myController', function() { 
'use strict'; 

var controller, scope; 

beforeEach(inject(function($rootScope, $controller) { 
    controller = $controller; 
    scope = $rootScope.$new(); 
})); 

describe('sum', function() { 
    it('1 + 1 should equal 2', function() { 
     expect(scope.listingsBarController()).toBe(2); 
    }); 
}); 
}); 

它说不确定是不是一个函数(在评估scope.listingsBarController。

有什么不对?

回答

0

你没有注入控制器。你需要稍微不同的注入控制器。做如下面前每个。

controller= $controller('myController', {$scope: scope}); 
相关问题