Я новичок в модульном тестировании с жасмином, поэтому я надеюсь, что это имеет смысл и является достаточно правильным, чтобы получить ответ, я пытаюсь проверить директиву angularJS
вот мой плункер: http://jsfiddle.net/ksqhmkqm/13
в моем случае я не могу получить вход (id = "Montid") значение в жасмине
вот мой код angualr
app.directive("monthNext", function () {
console.log('massif');
return {
restrict: 'A',
link: function (scope, element) {
element.on('input', function () {
var todaysYear = new Date();
var u = todaysYear.getFullYear() - 2;
if (element.val().length == 4) {
var nextElement = element.next().next().next().next().next().next().next();
nextElement = angular.element(document.querySelectorAll('#Montid'));
if (element.val() <= u) {
console.log(element.children());
//var nextElement = angular.element(document.body).find('[tab index = 6]')
console.log(nextElement);
//nextElement.focus();
console.log(nextElement);
nextElement.val("");
nextElement[0].focus();
} else {
// alert(nextElement.val());
console.log(nextElement.val("01"));
}
}
});
}
};
});
вот мой код жасмина
describe('CommonBusInfo', function () {
var element, scope, timeout;
beforeEach(function () {
module('CommonBusInfo');
inject(function ($rootScope, $compile) {
scope = $rootScope.$new();
element = angular.element('<form><input id="Montid" ng-model="test" value="09" type="text"/><input id="yearId" " type="text" value="2015" month-next/></form>');
$compile(element)(scope);
scope.$digest();
});
});
it('should set Month value to 1', function () {
var x = element.find('input');
x.triggerHandler('input');
scope.$digest();
});
});
Я хочу прочитать значение Montid для сравнения
Спасибо, Чайтанья
Вы можете получить атрибут с помощью функции attr
it('should set Month value to 1', function () {
var x = element.find('input');
var inputId = x.attr('id');
expect(inputId).toBe('Montid');
});