mirror of https://github.com/n2geoff/testit.git
refactored to support browser and nodejs. also seperated out execution to a run() to allow loading tests from files
This commit is contained in:
parent
5faca9e998
commit
ba94c435ad
|
@ -1,7 +1,19 @@
|
||||||
'use strict';
|
/* Test.it v 0.5 | MIT | https://github.com/n2geoff/testit */
|
||||||
|
(function(root, factory) {
|
||||||
|
// support browser & commonjs
|
||||||
|
if(typeof module === "object" && module.exports) {
|
||||||
|
module.exports = factory(root.test);
|
||||||
|
} else {
|
||||||
|
root.test = factory(root.test);
|
||||||
|
}
|
||||||
|
}(this, function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
const test = {
|
const test = {
|
||||||
it: function(tests, next) {
|
_tests: {},
|
||||||
|
run: function(next) {
|
||||||
|
|
||||||
|
let tests = this._tests;
|
||||||
// capture results
|
// capture results
|
||||||
let failed = [];
|
let failed = [];
|
||||||
let passed = [];
|
let passed = [];
|
||||||
|
@ -38,9 +50,16 @@ const test = {
|
||||||
return failed.length ? false : true;
|
return failed.length ? false : true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
it: function(tests) {
|
||||||
|
this._tests = tests;
|
||||||
|
return this;
|
||||||
|
},
|
||||||
assert: function (e, a) { if (e != a) throw Error(`expected ${e} == ${a}`); },
|
assert: function (e, a) { if (e != a) throw Error(`expected ${e} == ${a}`); },
|
||||||
equals: function (e, a) { if (e !== a) throw Error(`expected ${e} === ${a}`); },
|
equals: function (e, a) { if (e !== a) throw Error(`expected ${e} === ${a}`); },
|
||||||
exists: function (v) { if (!v) throw Error(`exists value ${v}`); },
|
exists: function (v) { if (!v) throw Error(`exists value ${v}`); },
|
||||||
pass: function () { return true; },
|
pass: function () { return true; },
|
||||||
fail: function (m) { throw Error(m); }
|
fail: function (m) { throw Error(m); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return test;
|
||||||
|
}));
|
||||||
|
|
Loading…
Reference in New Issue