JSFiddle - React, Tailwind, and code Playground

by karim79

HTML

<div id='results'></div>
<br />
<div id='console'></div>

JavaScript

var TestSuite = (function() {

    var assertImpl = (function() {
        var equals = function equals(a, b) {
            return a === b;
        };
        var notEquals = function notEquals(a, b) {
            return a !== b;
        };
        var doTest = function(a, b, fn, comment) {

            var testResult = fn(a, b);
            var resultsDiv = document.getElementById('results');
            var p = document.createElement('p');
            p.style.color = testResult ? 'blue' : 'red';
            p.innerHTML = 'a: ' + printVar(a) + ', ' + 'b: ' + printVar(b) + ', ' + fn.name + ' --> ' + testResult + (!testResult ? ' (Oops!)' : ' (Hooray!)');
            resultsDiv.appendChild(p);

            if (comment) {
                log('*** Tester\'s comment: ' + comment + ' ***');
            }

        };
        var printVar = function(value) {
            return typeof value === 'string' ? '"' + value + '"' : value;
        };
        return {
            equals: function(a, b, comment) {
                doTest(a, b, equals, comment);
            },
            notEquals: function(a, b, comment) {
                doTest(a, b, notEquals, comment);
            }
        };
    }());

    // makeshift console writer
    var log = function(output) {
        var consoleDiv = document.getElementById('console');
        var p = document.createElement('p');
        p.innerHTML = output;
        consoleDiv.appendChild(p);
    };

    var moduleImpl = (function() {
        return {
            test: function(assertion, assert) {
                log('Testing: ' + assertion);
                assert(assertImpl);
            },
            before: function(fn) {
                fn();
            }
        };
    }());

    return {
        module: function(assertion, module) {
            log('Testing: ' + assertion);
            module(moduleImpl);
        }
    };
}());


// code provided by numberfour
TestSuite.module("Module A", function(module) {
   ...