mithril-vndb/tests/test.js
Eirik S. Morland 3c34d8d6ed Fix a typo.
2014-03-23 08:44:10 +01:00

16 lines
477 B
JavaScript

function test(condition) {
try {if (!condition()) throw new Error}
catch (e) {console.error(e);test.failures.push(condition)}
test.total++
}
test.total = 0
test.failures = []
test.print = function(print) {
for (var i = 0; i < test.failures.length; i++) {
print(test.failures[i].toString())
}
print("tests: " + test.total + "\nfailures: " + test.failures.length)
if (test.failures.length > 0) {
throw new Error(test.failures.length + " tests did not pass.")
}
}