JSFiddle - React, Tailwind, and code Playground

by Daniel Lizik

JavaScript

var sandwich = (function(assert) {

  var accumulator = [], i;
  
  function Suite(conf) {
    this.should = conf.should;
    this.curr = { it: conf.it[i][0], result: conf.it[i][1].call(this), expected: [] };
    this.specs = [];
    for (i = 0; i < conf.it.length; i++) 
      this.specs.push(this.curr);
  }
  
  Suite.prototype.assert = assert;

	return {
  	Suite: Suite
  };

})(function assert(a, b) {
  var last = this.specs[this.specs.length - 1];
  console.log(this.specs)
  try {
    if (!a)
    	throw new Error('missing first argument');
    if (!b)
      throw new Error('missing second argument');
  	if (a !== b)
      throw new Error(a + ' should equal ' + b);
  }
  catch(e) {
    last.expected.push(e);
  }
  last.expected.push(a === b)
});

var test = new sandwich.Suite({
	should: 'do some stuff',
  it: [
  	['adds two numbers', function() {
    	this.assert(1 + 1, 2);
      this.assert(0, 1);
    }]
  ]
});