As i am new to unit testing , I want to test my javascript code its very confusing .. i really want some ones help who could tell the solution for my problem .??
if (!Notification) {
Notification = {};
else {
if (typeof Notification != "object") {
throw new Error(" already exists ");
}
}
Notification.admin = function() {
var res = {};
var prevent = "";
var DefaultValue = function(ans, type, commnon, status) {
var notify = type.concat(common);
if ($("#method").val() == "false" && type == "Text") {
if (status) {
return data = '<label class="checkbox-label"><input data-role="ux-checkbox" type="checkbox" disabled="disabled" data-type="' + notify + '" class="grid-checkbox">  </label>';
} else {
return data = '<label class="checkbox-label">' + '<span class="no-checkbox-label" >' + "-" + '</span>' + '</label>';
}
} else if (status) {
if (ans) {
return data = '<label class="checkbox-label"><input data-role="ux-checkbox" checked=checked type="checkbox" data-type="' + notify + '" class="grid-checkbox ">  </label>';
} else {
return data = '<label class="checkbox-label"><input data-role="ux-checkbox" type="checkbox" data-type="' + notify + '" class="grid-checkbox">  </label>';
}
} else {
return data = '<label class="checkbox-label">' + '<span class="no-checkbox-label" >' + "-" + '</span>' + '</label>';
}
};
this.init = function() {
};}; Notification.Obj = new Notification.admin();
$(document).ready(function() {
Notification.Obj.init();
});
This is my private function which i want to unit test as i am using mocha and chai ..
i am not able to unit test this function
private functionasprivate method. Your code example is not really shining light on what the snipplet is supposed to do and what you want to test. It appears to me that you may be confusing unit testing (very easy to setup, do not cover integration of services) and functional browser testing (automated browser click through). Your question my hence either be too broad or actually an XY-problem on your attempted solution.DefaultValuefunctioon as a closure within the admin function, but make it importable. You also have a side-effect via your jquery selector$("#method").va, that should be passed into that function instead so you can mock it. Then it should become a function that expects 5 inputs value and creates a label tag string, for which you then can test.