Friday, 13 September 2013

Javascript Unit Testing AutoComplete Functions

Javascript Unit Testing AutoComplete Functions

I am at a loss for how to start javascript unit testing this function. I
have a function that's called to set up a jQuery autocomplete field but
with in its 'source' and 'select' I make other function calls and there is
a success callback too.
It seems like it would be good practice to write some tests that essential
ensure those are being called correctly. However, is there a point to
testing these? In my other tests you just stub out the call to this
function so it's still showing up as not covered obviously.
What if any tests would make sense to write for this function?
self.setNameAutocomplete = function () {
$("#name").autocomplete({
minLength: 0,
source: self.NameArrayFromSuggestions,
select: function (event, ui) {
$("#name").val('');
NameSuggestion.getData(ui.item[2], self.AddName, function () {
$('#Message').text("Error Occured");
});
return false;
}
}).bind('focus', function () { $(this).autocomplete("search");
}).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li></li>").data("item.autocomplete", item).append("<a
class=\"name-type-ahead\">" + item[0] + "<br>" + item[1] +
"</a>").appendTo(ul);
};
};

No comments:

Post a Comment