assertion in Javascript
They just throws an Error when the assertion is not satisfied.
function greaterThan(a,b) {
console.assert(a > b, {"message":"a is not greater than b","a":a,"b":b});
}
greaterThan(5,6);
function plus1(a){
return a + 1;
}
function assertEqual(then, expected) {
if (result == expected) {
console.log("The assertion was successful")
} else {
console.log("The assertion was not successful. then="+then+", expected="+expected)
}
}
var result = plus1(1);
var expectation = 2;
assertEqual(result, expectation);