Skip to content

Instantly share code, notes, and snippets.

@angel333
Created November 4, 2016 20:52
Show Gist options
  • Save angel333/bca5b05362ec65bb24802a8b7544251a to your computer and use it in GitHub Desktop.
Save angel333/bca5b05362ec65bb24802a8b7544251a to your computer and use it in GitHub Desktop.
<script src='bench.js'></script>
if (undefined === window.testMeTests)
window.testMeTests = [];
Function.prototype.testMe = function (input, expected) {
testMeTests.push({
unit: this,
input: input,
expected: expected,
});
return this;
}
window.setInterval(function() {
var results = window.testMeTests.map(function(test) {
var result = test.unit.apply(null, test.input)
return Object.assign({}, test, {
result: result,
ok: result === test.expected
});
});
document.open();
results.forEach(function (result) {
document.write('<pre style=\'color:'+(result.ok?'green':'red')+'\'>');
document.write(JSON.stringify(result, null, ' '));
document.write('</pre>');
});
}, 300)
// Open DevTools and modify this function...
var add = function(a,b) {
return a + b;
}
.testMe([1, 2], 3)
.testMe([1, -1], 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment