testit/dist/testit.min.js

2 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2018-12-02 09:30:08 +00:00
/*! 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});