added to.be.ok() shorthand

This commit is contained in:
Geoff Doty 2019-01-13 16:47:12 -05:00
parent e25707b493
commit b1bd8bf47d
4 changed files with 15 additions and 10 deletions

7
dist/testit.js vendored
View File

@ -1,5 +1,5 @@
/*! Test.it v 0.8.0 | MIT | https://github.com/n2geoff/testit */
(function (root, factory) {
;(function (root, factory) {
"use strict";
if (typeof module === "object" && module.exports) {
module.exports = factory(root.test);
@ -29,10 +29,8 @@
passed.push(`\n+OK ${name}`);
} catch (err) {
if (errors) {
console.log('ERRORS: YES');
failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`);
} else {
console.log('ERRORS: NO');
failed.push(`\n-ERR ${name}`);
}
}
@ -75,6 +73,9 @@
throw new Error(`expected ${typeof val} to be an ${type}`);
}
},
"ok": () => {
return test.expects(val).to.exist();
},
"like": (comp) => {
if(val != comp) {
throw new Error(`expected ${val} == ${comp}`);

2
dist/testit.min.js vendored
View File

@ -1,2 +1,2 @@
/*! Test.it v 0.8.0 | MIT | https://github.com/n2geoff/testit */
!function(t,e){"use strict";"object"==typeof module&&module.exports?module.exports=e(t.test):t.test=e(t.test)}(this,function(){"use strict";const t={_tests:{},run:function(t,e){"boolean"!=typeof t&&(e=t,t=!0);let o=this._tests,n=[],r=[];return Object.keys(o).forEach(e=>{let s=o[e];try{s(),r.push(`\n+OK ${e}`)}catch(o){t?(console.log("ERRORS: YES"),n.push(`\n-ERR ${e} \n --- \n ${o.stack} \n ---`)):(console.log("ERRORS: NO"),n.push(`\n-ERR ${e}`))}}),"function"==typeof e?e({pass:r,fail:n}):(console.log(...r,...n),console.log(`\n# tests ${n.length+r.length} pass ${r.length} fail ${n.length}`),!n.length)},it:function(t){return this._tests=t,this},expects:function(e){return{to:{be:{a:o=>t.expects(e).to.be.an(o),an:t=>{if(-1!==["array"].indexOf(t)){if("array"!==e.constructor.name.toLowerCase())throw new Error(`expected ${typeof e} to be an ${t}`);return!0}if(typeof e!==t)throw new Error(`expected ${typeof e} to be an ${t}`)},like:t=>{if(e!=t)throw new Error(`expected ${e} == ${t}`)}},equal:t=>{if(e!==t)throw new Error(`expected ${e} === ${t}`)},exist:()=>{if(!e)throw new Error(`expected ${e} to be truthy`)},pass:()=>!0,fail:t=>{throw new Error(t)}}}}};return t});
!function(t,e){"use strict";"object"==typeof module&&module.exports?module.exports=e(t.test):t.test=e(t.test)}(this,function(){"use strict";const t={_tests:{},run:function(t,e){"boolean"!=typeof t&&(e=t,t=!0);let o=this._tests,r=[],n=[];return Object.keys(o).forEach(e=>{let s=o[e];try{s(),n.push(`\n+OK ${e}`)}catch(o){t?r.push(`\n-ERR ${e} \n --- \n ${o.stack} \n ---`):r.push(`\n-ERR ${e}`)}}),"function"==typeof e?e({pass:n,fail:r}):(console.log(...n,...r),console.log(`\n# tests ${r.length+n.length} pass ${n.length} fail ${r.length}`),!r.length)},it:function(t){return this._tests=t,this},expects:function(e){return{to:{be:{a:o=>t.expects(e).to.be.an(o),an:t=>{if(-1!==["array"].indexOf(t)){if("array"!==e.constructor.name.toLowerCase())throw new Error(`expected ${typeof e} to be an ${t}`);return!0}if(typeof e!==t)throw new Error(`expected ${typeof e} to be an ${t}`)},ok:()=>t.expects(e).to.exist(),like:t=>{if(e!=t)throw new Error(`expected ${e} == ${t}`)}},equal:t=>{if(e!==t)throw new Error(`expected ${e} === ${t}`)},exist:()=>{if(!e)throw new Error(`expected ${e} to be truthy`)},pass:()=>!0,fail:t=>{throw new Error(t)}}}}};return t});

View File

@ -1,5 +1,5 @@
/*! Test.it v 0.8.0 | MIT | https://github.com/n2geoff/testit */
(function (root, factory) {
;(function (root, factory) {
"use strict";
// support browser & commonjs
if (typeof module === "object" && module.exports) {
@ -34,10 +34,8 @@
passed.push(`\n+OK ${name}`);
} catch (err) {
if (errors) {
console.log('ERRORS: YES');
failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`);
} else {
console.log('ERRORS: NO');
failed.push(`\n-ERR ${name}`);
}
}
@ -81,6 +79,9 @@
throw new Error(`expected ${typeof val} to be an ${type}`);
}
},
"ok": () => {
return test.expects(val).to.exist();
},
"like": (comp) => {
if(val != comp) {
throw new Error(`expected ${val} == ${comp}`);

View File

@ -4,6 +4,7 @@ test.it({
"'like' should do truthy evaluation via ==": function() {
test.expects(1).to.be.like('1');
test.expects("1").to.be.like(1);
test.expects(1).to.be.ok();
},
"'equal' should do === evaluation exist": function() {
test.expects(1).to.equal(1);
@ -19,8 +20,10 @@ test.it({
test.expects().to.pass();
}
},
"you should be able to see if something 'exists'": function() {
"you should be able to test if something 'exists'": function() {
test.expects({}).to.exist();
test.expects({}).to.be.ok();
test.expects({}).to.be.a('object');
},
"should be able to check types": function() {
test.expects(123).to.be.a('number');