我一直收到错误:Object <Scope> has no method
我已经环顾四周并尝试了一切。
这是我的茉莉花:
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;
};
我似乎无法弄清楚这一点。我仔细检查了我的拼写,查看了其他示例,这应该有效。
答案 0 :(得分:0)
我可以看到的最大问题是您忘记在测试中加载模块。像这样:
beforeEach(module('yourModule'));
看看这个working demo和not working demo(它有完全相同的问题)