我正在使用以下规范测试Angular指令:
'use strict';
describe('playerInfo directive', function() {
var element;
var scope;
beforeEach(module('gameApp'));
beforeEach(module('templates'));
beforeEach(inject(function($rootScope, $compile) {
scope = $rootScope.$new();
element = '<player-info></player-info>';
element = $compile(element)(scope);
scope.digest();
}));
it('should replace the element with the appropriate content', function() {
expect(element.html()).toContain('Score:');
});
});
和我的指示:
'use strict';
angular.module('gameApp')
.directive('playerInfo', playerInfo);
function playerInfo() {
var directive = {
link: link,
restrict: 'E',
replace: true,
templateUrl: '/app/player/playerInfo.directive.html',
controller: 'PlayerInfoController',
controllerAs: 'playerInfo'
};
return directive;
function link(scope, element) {
var address = angular.element(element[0].getElementsByClassName('blur'));
address.on('click', function() {
address.css({'-webkit-filter': 'none'});
});
}
}
我一直看到的错误是TypeError: 'undefined' is not an object (evaluating 'moment.utc')
。
<div>{{playerInfo.game.date | amDateFormat: 'MMMM Do, YYYY'}} - <b am-time-ago="playerInfo.game.date"></b></div>
这似乎导致错误,但我不知道如何解决它。我已将src/assets/bower_components/moment/moment.js
和src/assets/bower_components/angular-moment/angular-moment.js
添加到files
的{{1}}数组中。
答案 0 :(得分:0)
问题是我在karma.config.js
中声明必要文件的顺序。 moment
之前需要angular-moment
来:
files: [
...
'src/assets/bower_components/moment/moment.js',
'src/assets/bower_components/angular-moment/angular-moment.js',
...
],