angular-material に依存するアプリがありますngMaterial
var sequencesApp = angular.module('sequencesApp', ['ngMaterial']);
sequencesApp.controller('SequenceListCtrl', function ($scope) {
$scope.sequences = [
{'name': 'Sequence 1',
'sequence': 'actgactgcatgctgctagctgcatgcta'},
{'name': 'Sequence 2',
'sequence': 'atgcatcatcatcatctctgcatgcatcatctacacataatagcatcgatctcatctcacacatgcatgctgcatcta'},
{'name': 'Sequence 3',
'sequence': 'atgcatacatcatcatctctgcatgcatcatctacacataatagcatcgatctcatctcacacatgcatgctgcatctaatgcatcatcatcatctctgcatgcatcatctacacataatagcatcgatctcatctcacacatgcatgctgcatctaatgcatcatcatcatctctgcatgcatcatctacacataatagcatcgatctcatctcacacatgcatgctgcatctaatgcatcatcatcatctctgcatgcatcatctacacataatagcatcgatctcatctcacacatgcatgctgcatctaatgcatcatcatcatctctgcatgcatcatctacacataatagcatcgatctcatctcacacatgcatgctgcatcta'}
];
});
次のテストコードでジャスミンとカルマを使用してテストを実行しています
describe('SequenceListCtrl', function(){
beforeEach(module('sequencesApp'));
var $controller;
beforeEach(inject(function(_$controller_){
// The injector unwraps the underscores (_) from around the parameter names when matching
$controller = _$controller_;
}));
describe('$scope.sequences', function() {
beforeEach(function () {
$scope = {};
$controller = $controller('SequenceListCtrl', { $scope: $scope });
});
it('should create "sequences" model with 3 sequences', function () {
expect($scope.sequences.length).toBe(3);
});
});
});
実行するとkarma start
、次のエラーが発生します。
Error: ngMaterial requires HammerJS to be preloaded.
at MdCoreInitialize (/Users/rhysalgar/Dropbox/Projects/LabGeniusApp/bower_components/angular-material/angular-material.js:21:11)
at Object.invoke (/Users/rhysalgar/Dropbox/Projects/LabGeniusApp/bower_components/angular/angular.js:4138:17)
at /Users/rhysalgar/Dropbox/Projects/LabGeniusApp/bower_components/angular/angular.js:3960:71
at forEach (/Users/rhysalgar/Dropbox/Projects/LabGeniusApp/bower_components/angular/angular.js:322:20)
at Object.createInjector [as injector] (/Users/rhysalgar/Dropbox/Projects/LabGeniusApp/bower_components/angular/angular.js:3960:3)
at Object.workFn (/Users/rhysalgar/Dropbox/Projects/LabGeniusApp/bower_components/angular-mocks/angular-mocks.js:2337:52)
TypeError: undefined is not a function
at Object.<anonymous> (/Users/rhysalgar/Dropbox/Projects/LabGeniusApp/media/development/test/controllers.test.js:20:25)
TypeError: Cannot read property 'length' of undefined
at Object.<anonymous> (/Users/rhysalgar/Dropbox/Projects/LabGeniusApp/media/development/test/controllers.test.js:24:34)
ngMaterial
アプリモジュールの依存関係を削除すると、すべて正常に動作します。
私のkarma.conf.js
ファイルには次のfiles
配列があります:
files: [
'test-main.js',
'bower_components/angular/angular.js',
'bower_components/angular-aria/angular-aria.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/hammerjs/hammer.js',
'bower_components/angular-material/angular-material.js',
'bower_components/angular-mocks/angular-mocks.js',
'media/development/js/*.js',
'media/development/test/*.js'
],