應用程序中的所有內容都能正常工作,所以它只是我的語法錯誤的測試。這是我正在處理的截斷版本。名稱和地點已更改,以保護無辜者。JasmineJS無法識別我注入的模塊
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'
奇怪!因爲我的整個應用程序都能正常工作,並且能夠完美實現該方法,所以一定是我沒有正確注入這個模塊(猜測!)。
Pkozlowski,這是不可思議的。非常感謝你的幫助。您的工作對Angular社區給予了巨大的幫助。 – Trip