繁体   English   中英

因果错误:找不到变量:角度

[英]Karma error: Can't find variable: angular

我正在尝试在一个项目中运行业力一周。 我已经按照本教程AngularJS单元测试进行了操作,但是在运行业力启动时 ,控制台显示此错误:

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  ReferenceError: Can't find variable: angular
  at /home/user/workspace/UnitTest/app/app.js:1

我以为问题出在我的项目中,所以我创建了一个新项目,错误仍然存​​在。

我的karma.conf.js

module.exports = function(config) {
config.set({
   basePath: '',
  frameworks: ['jasmine'],
files: [
  'app/*.js', 
  'tests/*.js',
  'node_modules/angular/angular.js', 
  'node_modules/angular/angular.min.js',
  'node_modules/angular-mocks/angular-mocks.js'
],

exclude: [
],

preprocessors: {
},
reporters: ['progress'],

// web server port
port: 9876,

colors: true,

logLevel: config.LOG_INFO,

autoWatch: true,

browsers: ['PhantomJS'], 

customLaunchers: {
  Chrome_without_security: {
    base: 'PhantomJS',
    flags: ['--disable-web-security']
  }
},

singleRun: false,

concurrency: Infinity
})
}

app.js

angular.module('MyApp', [])
  .filter('reverse',[function(){
    return function(string){
    return string.split('').reverse().join('');
   }
}])

我也尝试过更改节点版本,但是没有用。

解决方案是将角导入放在应用文件之前,如下所示:

files: [
  'node_modules/angular/angular.js', 
  'node_modules/angular/angular.min.js',
  'node_modules/angular-mocks/angular-mocks.js',
  'app/*.js', 
  'tests/*.js'
]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM