JSFiddle - React, Tailwind, and code Playground

by Daniel Lizik

JavaScript

(function(global, appName, factory) {
  'use strict';

  if (global.module && typeof global.module.exports === 'object')
    return module.exports = factory();
  if (global.define && typeof global.define === 'function')
    return define(appName, [factory()]);
  return global[appName] = factory();

})(this, 'sandwich', function() {

  function assert(a, b) {
    if (!a)
      throw new Error('missing argument' + JSON.stringify(arguments, null, 2))
    if (!b)
      throw new Error('missing argument' + JSON.stringify(arguments, null, 2))
    if (a !== b)
      throw new Error('arguments do not equal one another');
    return true;
  }

  function Suite(test) {
    var i
    this.it = test.it;
    this.tests = [];
    for (i = 0; i < test.specs.length; i++) {
      this.tests.push({
        expect: test.specs[i][0],
        actual: null
      });
      test.specs[i][1].call(this); 
    }
  }

  Suite.prototype.assert = function() {
    var result, curr = this.tests[this.tests.length - 1], prev = this.tests[this.tests.length - 2];
    console.log(prev)
    if (prev) {
      if (typeof prev.actal !== 'boolean')
      	return;
    }
    try {
      result = assert.apply(this, arguments);
    }
    catch(e) {
      return curr.actual = {
        args: Array.prototype.slice.call(arguments),
        err: e
      };
    }
    return curr.actual = result;
  };

  return {
    Suite: Suite
  }



});

//var sandwich = require('./sandwich');

var test = new sandwich.Suite({
  it: 'adds two numbers',
  specs: [
    ['should add 1 + 1', function() {
      this.assert(1, 1);
    }],
    ['should not add null and null', function() {
      this.assert(2, 3);
    }],
    ['should do multiple assertions', function() {
    	this.assert(0, 1);
      this.assert('bob', 'bob');
    }]
  ]
});