javascript - Karma error: Can't find variable: angular - Stack Overflow

I'm trying for a week run karma in a project. I've follow this tutorial AngularJS Unit Test b

I'm trying for a week run karma in a project. I've follow this tutorial AngularJS Unit Test but when run karma start the console shows this error:

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

I thought the problem was in my project, so i've created a new one and the error persists.

My karma.conf.js is

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
})
}

and app.js

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

I've tried to change the node version too, but it isn't worked.

I'm trying for a week run karma in a project. I've follow this tutorial AngularJS Unit Test but when run karma start the console shows this error:

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

I thought the problem was in my project, so i've created a new one and the error persists.

My karma.conf.js is

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
})
}

and app.js

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

I've tried to change the node version too, but it isn't worked.

Share Improve this question edited Jun 21, 2017 at 17:34 Denys Wylliam asked Jun 21, 2017 at 17:27 Denys WylliamDenys Wylliam 1292 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

The solution was put the angular imports before the app files like this:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745197865a4616180.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信