3

私のアプリは、をjRuby/Rails使用しています。javascript をテストして(aka )で実行したいのですが、 Angular モジュールがどこにも定義されていないというエラーが表示されます。私が持っているもの:インストールして、構成ファイルを生成しました:AngularJSCoffeScriptJasmineKarmaTestacularNode.jsKarma

// base path, that will be used to resolve files and exclude
basePath = '../';


// list of files / patterns to load in the browser
files = [
  JASMINE,
  JASMINE_ADAPTER,
  'vendor/assets/javascripts/angular.js',
  'vendor/assets/javascripts/angular-mocks.js',
  'vendor/assets/javascripts/angular-resource.js',
  'app/assets/javascripts/*.js.coffee',
  'spec/javascripts/*_spec.js'
];

preprocessors = {
  '**/*.coffee': 'coffee'
};

AngularJSソースファイル(モジュールと注入が機能するように)、JavaScriptアセット(CoffeScript)、および仕様を追加しました。CoffeScriptまた、プリプロセッサとして追加しました。

私の仕様ファイル:

describe("PasswordResetsController", function() {
  //Mocks
  var http = {};
  var routeParams = {};

  //Controller
  var ctrl = null;

  //Scope
  var $scope = null;

  beforeEach( function() {
    angular.module('KarmaTracker');
  });

  /* IMPORTANT!
   * this is where we're setting up the $scope and
   * calling the controller function on it, injecting
   * all the important bits, like our mockService */
  beforeEach(angular.inject(function($rootScope, $httpBackend, $controller) {
    //create a scope object for us to use.
    $scope = $rootScope.$new();

    //http mock from Angular
    http = $httpBackend;


    //now run that scope through the controller function,
    //injecting any services or other injectables we need.
    ctrl = $controller(PasswordResetsController, {
      $scope: $scope,
      $http: http,
      $routeParams: routeParams
    });
  }));


  it("foo spec", function() {
    expect($scope.foo).toEqual('test');
  });
});

モジュールを angular.module でロードし、依存関係を注入し、$http と routeParams をモックしています。

私のモジュール定義は次のようになります。

window.KarmaTracker = angular.module('KarmaTracker', ['ngCookies', 'ngMobile'])

# Flashe message passed from other controllers to FlashesController
KarmaTracker.factory "FlashMessage", ->
  { string: "", type: null }

KarmaTracker.controller "RootController", ($scope, $http, $location, $cookies, $routeParams, FlashMessage, broadcastService) ->
.....

モジュールは KarmaTracker 名前空間にロードされています。これが原因だと思います。Karma を次のコマンドで開始する場合:

karma start --log-level debug config/karma.conf.js

アセットがコンパイルされてサーバー化されていることがわかりますが、次のメッセージが表示されます。

PhantomJS 1.8 (Linux) ERROR
        ReferenceError: Can't find variable: KarmaTracker
        at /home/.../KarmaTracker/app/assets/javascripts/account.js.coffee-compiled.js:1

今何をすべきかについてのアイデアは大歓迎です!

4

1 に答える 1

0

アセットをワイルドキャットでロードする代わりに、正しい順序で 1 つずつ指定してロードしようとしましたか? 順序がカルマに関係することは知っています。

于 2014-01-25T14:34:31.293 に答える