JSFiddle - React, Tailwind, and code Playground
JavaScript
'strict'
// test utils
window.onerror = function(error, url, line, col, errorObject) {
writeError(errorObject.stack);
};
window.UnitTest = {};
var runAllTests = function(){
for (var property in UnitTest) {
if (UnitTest.hasOwnProperty(property)) {
UnitTest[property]();
}
}
}
setTimeout(runAllTests);// to wait for all tests to be defined
function is(value2){ // for bdd
return value2;
}
function assertThat(value1, value2){
if(value1 !== value2){
throw new Error("Test error: " + value1 + " is not equal to " + value2);
}
}
function writeError(msg){
var errorPanel = document.getElementById("errorPanel");
if(errorPanel === null){
errorPanel = document.createElement('pre');
errorPanel.id = "errorPanel";
errorPanel.style.cssText = 'position:absolute;opacity:0.8;padding:5px;top:0px;color:white;z-index:100;background:#000;';
errorPanel.onclick = function(){
this.style.css += "left:3000px";
}
document.body.appendChild(errorPanel);
}
errorPanel.innerHTML = (msg + "<br>>");
}
// You might want start editing from here <--------------------
// prod code
function addition(a, b){
//return a + b;
return a - b;
}
//tests
UnitTest.should_add_two_numbers = function(){
assertThat(addition(1, 2), is(3));
}