0
我需要爲控制器中的方法編寫測試用例。在該控制器中,我使用的是this
而不是$scope
。如果我們使用$scope
,我們可以寫下如下的測試用例。但是如果我在控制器中使用this
,我該如何編寫測試用例。
app.controller('ExampleController', function(){
var test = this;
this.testFunction = function(){
return "Hello";
}
});
卡瑪測試用例文件
describe('app module', function() {
beforeEach(module('testAngularApp'));
describe('ContentController', function() {
var scope, controller;
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller;
controller('ContentController', {
$scope: $scope
});
it('Should return Hello', function() {
expect(scope.testFunction()).toBe(true);
});
});