业力误差:无法找到变量:angular

问题描述 投票:1回答:1

我正在尝试在项目中运行一周的业力。我按照本教程AngularJS Unit Test但在运行karma启动时控制台显示此错误:

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('');
   }
}])

我也试图改变节点版本,但它没有用。

javascript angularjs npm jasmine karma-runner
1个回答
4
投票

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

files: [
  'node_modules/angular/angular.js', 
  'node_modules/angular/angular.min.js',
  'node_modules/angular-mocks/angular-mocks.js',
  'app/*.js', 
  'tests/*.js'
]
© www.soinside.com 2019 - 2024. All rights reserved.