diff --git a/dist/testit.js b/dist/testit.js index 27ff03b..0781940 100644 --- a/dist/testit.js +++ b/dist/testit.js @@ -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}`); diff --git a/dist/testit.min.js b/dist/testit.min.js index d38a194..72456f0 100644 --- a/dist/testit.min.js +++ b/dist/testit.min.js @@ -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}); \ No newline at end of file +/*! 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,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}); \ No newline at end of file diff --git a/src/testit.js b/src/testit.js index 1722638..11b349b 100644 --- a/src/testit.js +++ b/src/testit.js @@ -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}`); diff --git a/test/index.spec.js b/test/index.spec.js index 27010c3..678ba31 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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'); @@ -30,4 +33,4 @@ test.it({ test.expects(false).to.be.a('boolean'); test.expects(undefined).to.be.a('undefined'); } -}); \ No newline at end of file +});