I'm testing an Angular directive using the following spec:
'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:');
});
});
and my directive:
'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'});
});
}
}
The error I keep seeing is TypeError: 'undefined' is not an object (evaluating 'moment.utc'). My controller utilizes moment in several places. How can I avoid this causing my tests to fail?
Aucun commentaire:
Enregistrer un commentaire