0
我不斷收到錯誤:Object <Scope> has no method
,我環顧四周,試了一下。茉莉花對象#<Scope>沒有方法
這裏是我的茉莉花:
var scope, service1, service2;
var EmployeeService_mock = function(){
var obj = {
visibleEmployees : [],
selectedEmployee : null
};
obj.setSelectedEmployee = function (emp) {
obj.selectedEmployee = emp;
};
return obj;
};
var EmpTreeNavigationService_mock = function(){
};
beforeEach(inject(function($rootScope, $controller){
scope = $rootScope.$new();
service1 = new EmployeeService_mock();
service2 = new EmpTreeNavigationService_mock();
$controller('EmployeesCtrl',
{
$scope: scope,
EmployeeService: service1,
EmpTreeNavigationService: service2
}
);
scope.$digest();
}));
it('should test', function(){
expect(scope.isSelectedEmployee(emp1)).toBeTruthy();
});
這裏是我的.js
$scope.isSelectedEmployee = function (emp) {
return true;
};
我似乎無法想出解決辦法。我已經加倍檢查拼寫,查看其他示例,這應該起作用。
它不會有什麼方法?錯誤消息看起來好像錯誤消息可能已被截斷。 – mfollett
對不起@mfollet,它沒有方法,isSelectedEmployee。我把這部分留下來了,因爲這個改變是基於我所調用的方法。它會拋出所有scope.blah調用的錯誤。 – user3339134