I am working in reverse in a system lifecycle. A few months ago I wrote a large javascript library. I then had to make it all objective and now, I have to write unit tests for it. I am using Maven and have the jasmine-maven-plugin
in my pom.xml. The problem I am having is what should I be writing tests for, and how many.
This first example is simple. The function takes a string and returns it with the first letter capitalised.
var toolsFn = {
capitaliseFirstLetter: function(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
},
and so my unit test it:
describe("toolsFn - capitaliseFirstLetter", function() {
it("capitalises the first letter of a given string", function() {
expect(toolsFn.capitaliseFirstLetter("hello World!")).toBe("Hello World!");
});
});
However, I am unsure what I should do for many of my other methods. The majority of them deal with the html code such as changing a tab, showing a notification, disabling/enabling controls. Should I just expect the method toHaveBeenCalled
or is there more to it than that?
Please check the following examples which changes tabs, loads a given tab and hides a notification;
tabsFn = {
changeTab: function() {
$(tabButtons).addClass('inactive');
$(tabContent).hide();
$(this).removeClass('inactive');
var tab = $(this).attr('tab');
$('.tab-content-' + tab).show();
return false;
},
loadTab: function(tab) {
$(tabButtons).addClass('inactive');
$(tabContent).hide();
$('[tab~="' + tab + '"]').removeClass('inactive').removeAttr('disabled');
$('.tab-content-' + tab).show();
},
messageFn = {
hideNotification: function(time) {
$(messageFn.notificationBar).stop(true, true).fadeOut(time);
},
Any clarification is much appreciated.