I am trying to implement '@ Users Feature' with angularjs, I almost finish the feature except writing an unit test. I have a Caret module which can help me get the caret position in textarea.
I think the most important thing is to get the caret position but I dont know how to do it in jasmine.
Mydirective
.directive('atUser', function (Caret) {
return {
restrict: 'A',
link: function (scope, element) {
element.bind('focus click keydown', function () {
scope.caretPos = Caret.getPos(element);
});
scope.$watch(function () {
return scope.caretPos;
}, function (nowCaretPos) {
/* do something here */
})
}
}
})
Html
<textarea ng-model="message" at-user></textarea>
Jasmine
describe('test at user', function () {
/* some init code */
it('should get caret postion', function () {
textarea = element.find('textarea');
textarea.triggerHandler('focus');
except(textarea.scope().caretPos).toEqual(0);
/*
* then i want to simulate keydown event and type something
* and get the caret postion
* but i dont know how to do it
* /
})
})
One more thing is I dont want to use jquery.
Can anyone help me?
thanks a lot!