I’m new to the mocha framework, I’m not completely getting out of it, I have set up my machine with that framework in visual studio 2017. I have below a sample piece of code however I’m not getting how to test the existing javascript code that is in .cshtml page that has page elements as well in it, please help.
///////////////////////////////////////////////
// SAmple Code of mocha
var assert = require('assert');
describe('Test Suite 1', function () {
it('Test 1', function () {
assert.ok(true, "This shouldn't fail");
});
it('Test 2', function () {
assert.ok(1 === 1, "This shouldn't fail");
assert.ok(false, "This should fail");
});
});
///////////////////////////////////////////////////////////////
// Our code inside .cshtml
function SerChr(val) {
var f = parseFloat(result1) + parseFloat(document.getElementById("body_SerPerInst").value)
document.getElementById("body_TotAmtPerInst").value = Math.floor(f);
totreturnamount = (parseFloat(num3) + (parseFloat(document.getElementById("body_TotAmtPerInst").value) * parseFloat(document.getElementById("body_TotInst").value)));
document.getElementById("body_TotRetAmt").value = totreturnamount;
var h = parseFloat(num2) + parseFloat(document.getElementById("body_SerPerInst").value);
document.getElementById("body_inst1").value = Math.floor(h);
}
2nd example
$("#form2").submit(function(e){
e.preventDefault();
if(validate()){
var formData = new FormData($(this)[0]);
$.ajax({
url: "addv.php",
type: 'POST',
data: formData,
success: function (data) {
$('.fv').html(data).hide().fadeIn(500).delay(1000).fadeOut(500);
},
contentType: false,
processData: false
});
} else {
alert('error');
}
});
// Another example
function validate()
{
var m=document.getElementById("mat").value;
var c=document.getElementById("kilo").value;
var v=true;
if(!isNaN(m))
{
alert("matricule doit etre une chaine !");
document.getElementById("mat").value=null;
v=false;
}
if(isNaN(c))
{
alert("kilométrage doit etre un entier !");
document.getElementById("kilo").value=null;
v=false;
}
return v;
}