アプリのすべてが正常に機能するため、構文的に間違っているのは私のテストだけです。ここに私が取り組んでいるものの切り詰められたバージョンがあります。罪のない人々を保護するために、名前と場所が変更されました。
var m;
m = angular.module('CustomService', []);
window.CustomService = m.factory("CustomService", function($rootScope) {
var sharedService;
sharedService = {};
sharedService.broadcastItem = function() {
return console.log('Works!');
};
return sharedService;
});
window.MyCtrl = function($scope, $location, CustomService) {
this.$inject = ['$scope', 'CustomService'];
return $scope.test_method = function(date) {
return CustomService.broadcastItem(date);
};
};
describe('MyCtrl', function() {
beforeEach(inject(function($rootScope, $controller, $location) {
this.scope = $rootScope.$new;
return this.controller = $controller(MyCtrl, {
$scope: this.scope,
$location: $location,
CustomService: CustomService
});
}));
return it('tests my method', function() {
return this.scope.test_method('10-1984');
});
});
そして、その最終行は次を返します:
TypeError: Object #<Object> has no method 'test_method'
変!私のアプリ全体が機能し、その方法が完璧に機能するという事実から繁栄しているからです. したがって、このモジュールを適切に注入していないに違いありません (推測!)。