我有以下测试:
describe("An Angularjs test suite",function(){
beforeEach(module('myApp'));
var scope,controller;
beforeEach(inject(function($rootScope,$controller){
scope = $rootScope.$new(),
controller = $controller('homeController',{$scope:scope});
}));
it('should return true',function(){
expect(scope.helloWorld()).toBe('hello');
});
});
在家庭控制器中我有这个:
$scope.helloWorld = function(){
return 'hello';
};
测试运行有问题并说“未定义不是函数”,问题是什么?
答案 0 :(得分:0)
(function (angular) {
// Create module
var myApp = angular.module('myApp', []);
myApp.controller('homeController', function($scope){
$scope.helloWorld = function(){
return 'hello';
};
});
})(angular);
// ---SPECS-------------------------
describe('myApp', function () {
beforeEach(module('myApp'));
var scope,controller;
beforeEach(inject(function($rootScope,$controller){
scope = $rootScope.$new(),
controller = $controller('homeController',{$scope:scope});
}));
it('should return true',function(){
expect(scope.helloWorld()).toBe('hello');
});
});
在这里创建一个TestCase。
它过去了。