私のアプリは、をjRuby/Rails
使用しています。javascript をテストして(aka )で実行したいのですが、 Angular モジュールがどこにも定義されていないというエラーが表示されます。私が持っているもの:インストールして、構成ファイルを生成しました:AngularJS
CoffeScript
Jasmine
Karma
Testacular
Node.js
Karma
// 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
今何をすべきかについてのアイデアは大歓迎です!