什么可能导致此错误?
Error: [$injector:modulerr] Failed to instantiate module fooApp due to:
TypeError: 'undefined' is not a function (evaluating '$stateProvider
.state')
编辑后+++
inject(function ($injector) {
MyService= $injector.get('MyService');
});
MyService = undefined为什么?
编辑帖子---
我的服务(提供商):
'use strict';
angular.module('fooApp')
.factory('MyService', function () {
var function1 = function function1(value) {
return value;
};
return {
function1: function1
};
});
我的测试:
'use strict';
describe('Service: MyService', function () {
beforeEach(module('fooApp'));
var MyService;
beforeEach(function(){
inject(function ($injector) {
MyService= $injector.get('MyService');
});
});
it('should ....', function(){
expect(MyService.function1('....')).toEqual(...);
.....
});
......
});
foo.js:
'use strict';
angular.module('fooApp')
.config(function ($stateProvider) {
$stateProvider
.state('foo', {
url: '/foo',
views: {
'content': {
templateUrl: 'app/foo/foo.html',
controller: 'FooCtrl'
},
'footer': {
templateUrl: 'components/footer/footer.html',
line 15: controller: 'FooterCtrl'
}
}
});
});
stacktrace:
Error: [$injector:modulerr] Failed to instantiate module fooApp due to:
TypeError: 'undefined' is not a function (evaluating '$stateProvider
.state')
at C:/_Projet/foo/client/app/foo/foo.js:15
at invoke (C:/_Projet/foo/client/bower_components/angular/angular.js:4182)
at runInvokeQueue (C:/_Projet/foo/client/bower_components/angular/angular.js:4088)
at C:/_Projet/foo/client/bower_components/angular/angular.js:4097
at forEach (C:/_Projet/foo/client/bower_components/angular/angular.js:323)
at loadModules (C:/_Projet/foo/client/bower_components/angular/angular.js:4120)
at createInjector (C:/_Projet/foo/client/bower_components/angular/angular.js:4004)
at workFn (C:/_Projet/foo/client/bower_components/angular-mocks/angular-mocks.js:2339)
http://errors.angularjs.org/1.3.8/$injector/modulerr?p0=fooApp&p1=TypeError%3A%20'undefined'%20is%20not%20a%20function%20(evaluating%20'%24stateProvider%0A%20%20%20%20%20%20%20%20%20%20%20%20.state')%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fclient%2Fapp%2Fauth%2Fauth.js%3Fb8f7bccdf2d8f57e6d6f0c810e0d1c6f0d3df707%3A15%0A%20%20%20%20at%20invoke%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fclient%2Fbower_components%2Fangular%2Fangular.js%3Febb86f089066f7089a249e390e64bcab67622158%3A4182)%0A%20%20%20%20at%20runInvokeQueue%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fclient%2Fbower_components%2Fangular%2Fangular.js%3Febb86f089066f7089a249e390e64bcab67622158%3A4088)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fclient%2Fbower_components%2Fangular%2Fangular.js%3Febb86f089066f7089a249e390e64bcab67622158%3A4097%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fclient%2Fbower_components%2Fangular%2Fangular.js%3Febb86f089066f7089a249e390e64bcab67622158%3A323)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fclient%2Fbower_components%2Fangular%2Fangular.js%3Febb86f089066f7089a249e390e64bcab67622158%3A4120)%0A%20%20%20%20at%20createInjector%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fclient%2Fbower_components%2Fangular%2Fangular.js%3Febb86f089066f7089a249e390e64bcab67622158%3A4004)%0A%20%20%20%20at%20workFn%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fclient%2Fbower_components%2Fangular-mocks%2Fangular-mocks.js%3Fb01a9cf8de7de4def103da067347cb07fe247c96%3A2339)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fnode_modules%2Fkarma-jasmine%2Flib%2Fjasmine.js%3F437512c57124d57f5ec77e2e82bfb4e3cdd15cce%3A1145%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fnode_modules%2Fkarma-jasmine%2Flib%2Fjasmine.js%3F437512c57124d57f5ec77e2e82bfb4e3cdd15cce%3A2177%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fnode_modules%2Fkarma-jasmine%2Flib%2Fjasmine.js%3F437512c57124d57f5ec77e2e82bfb4e3cdd15cce%3A2130%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fnode_modules%2Fkarma-jasmine%2Flib%2Fjasmine.js%3F437512c57124d57f5ec77e2e82bfb4e3cdd15cce%3A2460%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fnode_modules%2Fkarma-jasmine%2Flib%2Fjasmine.js%3F437512c57124d57f5ec77e2e82bfb4e3cdd15cce%3A2177%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fnode_modules%2Fkarma-jasmine%2Flib%2Fjasmine.js%3F437512c57124d57f5ec77e2e82bfb4e3cdd15cce%3A2130%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fnode_modules%2Fkarma-jasmine%2Flib%2Fjasmine.js%3F437512c57124d57f5ec77e2e82bfb4e3cdd15cce%3A2606%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fnode_modules%2Fkarma-jasmine%2Flib%2Fjasmine.js%3F437512c57124d57f5ec77e2e82bfb4e3cdd15cce%3A2177%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fnode_modules%2Fkarma-jasmine%2Flib%2Fjasmine.js%3F437512c57124d57f5ec77e2e82bfb4e3cdd15cce%3A2167
at C:/_Projet/foo/client/bower_components/angular/angular.js:4118
at forEach (C:/_Projet/foo/client/bower_components/angular/angular.js:323)
at loadModules (C:/_Projet/foo/client/bower_components/angular/angular.js:4120)
at createInjector (C:/_Projet/foo/client/bower_components/angular/angular.js:4004)
at workFn (C:/_Projet/foo/client/bower_components/angular-mocks/angular-mocks.js:2339)
app.js:
angular.module('fooApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ui.router',
'ui.bootstrap',
'pascalprecht.translate',
'restangular'
])
.........code........
karma.conf.js:
files: [
'client/bower_components/es5-shim/es5-shim.js',
'client/bower_components/modernizr/modernizr.js',
'client/bower_components/jquery/dist/jquery.js',
'client/bower_components/angular/angular.js',
'client/bower_components/angular-mocks/angular-mocks.js',
'client/bower_components/angular-resource/angular-resource.js',
'client/bower_components/angular-cookies/angular-cookies.js',
'client/bower_components/angular-sanitize/angular-sanitize.js',
'client/bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
'client/bower_components/angular-socket-io/socket.js',
'client/bower_components/angular-animate/angular-animate.js',
'client/bower_components/lodash/dist/lodash.compat.js',
'client/bower_components/angular-ui-router/release/angular-ui-router.js',
'client/bower_components/angular-ui-calendar/src/calendar.js',
'client/bower_components/toastr/toastr.js',
'client/bower_components/mocha/mocha.js',
'client/bower_components/angular-translate/angular-translate.js',
'client/bower_components/restangular/dist/restangular.js',
'client/bower_components/angular-cookie/angular-cookie.js',
'client/bower_components/angular-datatables/dist/angular-datatables.js',
'client/bower_components/angular-translate-loader-partial/angular-translate-loader- partial.js',
'client/app/app.js',
'client/app/**/*.js',
'client/components/**/*.js',
'client/app/**/*.html',
'client/components/**/*.html'
]
Bower.js:
{
"dependencies": {
"angular": "~1.3.7",
"jquery": "~2.1.1",
"json3": "~3.3.1",
"es5-shim": "~4.0.5",
"bootstrap-sass-official": "~3.1.1",
"bootstrap": "~3.3.1",
"angular-resource": "~1.3.6",
"angular-cookies": "~1.3.6",
"angular-sanitize": "~1.3.6",
"angular-bootstrap": "0.11.2",
"angular-translate-loader-partial": "2.5.2",
"angular-translate-storage-local": "2.5.2",
"font-awesome": "~4.1.0",
"lodash": "~2.4.1",
"angular-ui-router": "~0.2.11",
"angular-ui-calendar": "~0.8.*",
"metisMenu": "~1.1.3",
"restangular": "~1.4.0",
"blueimp-md5": "1.1.0",
"angular-cookie": "~4.0.6",
"angular-datatables": "~0.3.0",
"angular-ui-select": "0.9.5"
},
"devDependencies": {
"angular-mocks": "~1.3.8",
"angular-scenario": "~1.3.8"
}
}