diff --git a/dist/testit.min.js b/dist/testit.min.js index 240d176..c32c530 100644 --- a/dist/testit.min.js +++ b/dist/testit.min.js @@ -1,2 +1,2 @@ -/*! Test.it v 0.6.1 | 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){let e=this._tests,r=[],o=[];return Object.keys(e).forEach(function(t){let n=e[t];try{n(),o.push(`\n+ ${t}`)}catch(e){r.push(`\n- ${t}`),console.error(e)}}),"function"==typeof t?t({pass:o,fail:r}):(console.log(...o,...r),console.log(`\n# tests ${r.length+o.length} pass ${o.length} fail ${r.length}`),!r.length)},it:function(t){return this._tests=t,this},expects:e=>({to:{be:{a:r=>t.expects(e).to.be.an(r),an:t=>{if(-1!==["array"].indexOf(t)){if("array"===e.constructor.name.toLowerCase())return!0;throw new Error(`expected ${typeof e} to be an ${t}`)}if(typeof e===t)return!0;throw new Error(`expected ${typeof e} to be an ${t}`)},like:t=>{if(e==t)return!0;throw new Error(`expected ${e} == ${t}`)}},equal:t=>{if(e===t)return!0;throw new Error(`expected ${e} === ${t}`)},exist:()=>{if(e)return!0;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.6.2 | 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){let e=this._tests,r=[],o=[];return Object.keys(e).forEach(function(t){let n=e[t];try{n(),o.push(`\n+ ${t}`)}catch(e){r.push(`\n- ${t}`),console.error(e)}}),"function"==typeof t?t({pass:o,fail:r}):(console.log(...o,...r),console.log(`\n# tests ${r.length+o.length} pass ${o.length} fail ${r.length}`),!r.length)},it:function(t){return this._tests=t,this},expects:e=>({to:{be:{a:r=>t.expects(e).to.be.an(r),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 diff --git a/src/testit.js b/src/testit.js index e89e87e..57f1877 100644 --- a/src/testit.js +++ b/src/testit.js @@ -1,4 +1,4 @@ -/*! Test.it v 0.6.1 | MIT | https://github.com/n2geoff/testit */ +/*! Test.it v 0.6.2 | MIT | https://github.com/n2geoff/testit */ (function (root, factory) { "use strict"; // support browser & commonjs @@ -60,39 +60,31 @@ "an": (type) => { if(['array'].indexOf(type) !== -1) { - if(val.constructor.name.toLowerCase() === 'array') { - return true; - } else { + if(val.constructor.name.toLowerCase() !== 'array') { throw new Error(`expected ${typeof val} to be an ${type}`); } + + return true; } - if(typeof val === type) { - return true; - } else { + if(typeof val !== type) { throw new Error(`expected ${typeof val} to be an ${type}`); } }, "like": (comp) => { - if(val == comp) { - return true; - } else { + if(val != comp) { throw new Error(`expected ${val} == ${comp}`); } } }, "equal": (comp) => { - if(val === comp) { - return true; - } else { + if(val !== comp) { throw new Error(`expected ${val} === ${comp}`); } }, "exist": () => { - if(val) { - return true; - } else { + if(!val) { throw new Error(`expected ${val} to be truthy`); } },