I currently use jasmine to test my angularjs code and I have some autocomplete-like directive which should start to request data from server when a user has typed some chars into the input.
Now, here's my test code:
var element = linkingFn(scope);
var $input = $("input", element);
expect($input.length).toBe(1);
var keyVal = 111; // 'o'
$input.trigger({
type: 'keypress', keyCode: keyVal, which: keyVal, charCode: keyVal
});
keyVal = 110; // 'n'
$input.trigger({
type: 'keypress', keyCode: keyVal, which: keyVal, charCode: keyVal
});
keyVal = 101; // 'e'
$input.trigger({
type: 'keypress', keyCode: keyVal, which: keyVal, charCode: keyVal
});
// THIS DOES NOT WORK
expect($input.val()).toBe("one");
$input.val() is always empty. My understanding is that since it's not running in a browser there are no events fired (obviously) so the val() is not set. So what are my options here?