spec.js
'use strict';
describe('homeView', function () {
var $componentController;
var controller;
// loads the module
beforeEach(module('homeView'));
beforeEach(inject(function ($injector) {
$componentController = $injector.get('$componentController');
controller = $componentController('homeView', {
$scope: {},
$route: {},
EmpApi: "What should I write here???"
});
}));
//beforeEach(inject(function (_$componentController_) {
// $componentController = _$componentController_;
//}));
it('test number', function () {
expect(controller.number).toEqual(7);
});
});
module
angular.module('homeView', []);
component
angular.
module('homeView').
component('homeView', {
templateUrl: 'home-view/home-view.template.html',
controller: ['$scope', '$route', 'EmpApi',
function HomeViewController($scope, $route, EmpApi) {
this.number = 7;
}
]
});
EmpApi - это объект, возвращаемый фабрикой.Как мне протестировать этот контроллер с параметрами $ scope, $ route и EmpApi?Если я удаляю все о маршруте и Empapi, он прошел тест.Когда я их сохраняю, выдает эту ошибку
TypeError: EmpApi.getInterviewees is not a function
at <Jasmine>
at getInterviewees (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.js:15:28)
at new HomeViewController (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.js:13:17)
at Object.instantiate (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:5137:14)
at $controller (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:11688:28)
at C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular-mocks.js:2555:14
at $componentController (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular-mocks.js:2611:14)
at UserContext.<anonymous> (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.spec.js:13:22)
at Object.invoke (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:5122:19)
at UserContext.WorkFn (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular-mocks.js:3459:20)
at <Jasmine>
at window.inject.angular.mock.inject (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular-mocks.js:3422:25)
at Suite.<anonymous> (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.spec.js:11:16)
at <Jasmine>
at C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.spec.js:3:1
TypeError: Cannot read property 'number' of undefined
at <Jasmine>
at UserContext.<anonymous> (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.spec.js:28:27)
at <Jasmine>
getInterviewees - это функция в EmpApi, и я даже не вызываю ее нигде в этом фрагменте тестового кода.