testit/dist/testit.umd.min.js

1 line
1.2 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("umd",t):(e="undefined"!=typeof globalThis?globalThis:e||self).umd=t()}(this,function(){"use strict";const e={log:console.log,_tests:{},run:function(t,o){"boolean"!=typeof t&&(o=t,t=!0);let n=this._tests||[],r=[],s=[];return Object.keys(n).forEach(e=>{let o=n[e];try{o(),s.push(`\n+OK ${e}`)}catch(o){t?r.push(`\n-ERR ${e} \n --- \n ${o.stack} \n ---`):r.push(`\n-ERR ${e}`)}}),"function"==typeof o?o({pass:s,fail:r}):(e.log(...s,...r),e.log(`\n# tests ${r.length+s.length} pass ${s.length} fail ${r.length}`),!r.length)},it:function(e){return this._tests=e,this},expects:function(t){return{to:{be:{a:o=>e.expects(t).to.be.an(o),an:e=>{if(-1!==["array"].indexOf(e)){if("array"!==t.constructor.name.toLowerCase())throw new Error(`expected ${typeof t} to be an ${e}`);return!0}if(typeof t!==e)throw new Error(`expected ${typeof t} to be an ${e}`)},ok:()=>e.expects(t).to.exist(),like:e=>{if(t!=e)throw new Error(`expected ${t} == ${e}`)}},equal:e=>{if(t!==e)throw new Error(`expected ${t} === ${e}`)},exist:()=>{if(!t)throw new Error(`expected ${t} to be truthy`)},pass:()=>!0,fail:e=>{throw new Error(e)}}}}};return e});