业力测试调用时未定义角度错误 [英] angular is not defined error when karma test invoked

查看:68
本文介绍了业力测试调用时未定义角度错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定这与angular-mock.js有关,但由于一切似乎都很好,我无法确定我需要做什么.我只是通过角度种子应用程序的默认设置进行操作. 请帮助解决问题

I'm sure this has something to do with angular-mock.js but I cant figure what I need to do as everything seems to be fine. I'm just going by the default setup from angular-seed app. Please help get rid of the problem

karma.conf.js

module.exports = function(config){
  config.set({

    basePath : '../',

    files : [
      'bower_components/angular/angular.js',
      'bower_components/angular-route/angular-route.js',
      'bower_components/angular-mocks/angular-mocks.js',
      'app/js/**/*.js',
      'test/unit/**/*.js'
    ],

    autoWatch : true,

    frameworks: ['jasmine'],

    browsers : ['Chrome'],

    plugins : [
            'karma-chrome-launcher',
            'karma-firefox-launcher',
            'karma-jasmine'
            ],

    junitReporter : {
      outputFile: 'test_out/unit.xml',
      suite: 'unit'
    }

  });
};

controllers.js

'use strict';
/* Controllers */

var app = angular.module('myApp.controllers', []);
app.constant('RESTURL', 'http://'+ location.hostname + ':8003');

app.controller('MainCtrl', ['$scope', 'dataService', 'flash', 'mySharedService','facetSearchService', 'facetSelectionService', 'RESTURL',  function($scope, dataService, flash, sharedService, facetSearch, facet, RESTURL) {
      $scope.RESTURL =  RESTURL;
      $scope.loading = true;
      $scope.data = null;
      $scope.resultCount = 0;
      $scope.currentPage = 0;
      $scope.pageSize = 10;

          ....
])}

controllerSpec.js

'use strict';

/* jasmine specs for controllers go here */

describe('controllers', function(){
  beforeEach(module('myApp.controllers'));


  it('should test MainCtrl', inject(function($controller) {
    //spec body
    var scope = {},
    ctrl = $controller('MainCtrl', {$scope:scope});

    expect($scope.RESTURL).toBe('http://'+ location.hostname + ':8003'));
  }));


});

项目文件结构:

推荐答案

我相信您运行过"bower install"来安装依赖项吗?

I trust you ran "bower install" to install the dependencies?

bower_components的路径不正确.基本路径"../"将使业力在项目的根目录中显示,但bower_components位于"app"文件夹中. karma.conf中的文件"必须以"app"为前缀.

The paths to bower_components are incorrect. A basepath of "../" will make karma look in the root of your project but your bower_components are in your "app" folder. The "files" in karma.conf need to be prefixed with "app".

这篇关于业力测试调用时未定义角度错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆