Created
January 14, 2019 02:32
-
-
Save dennythecoder/32f7cc8efd1a0db7b5b9d07731cdc3e0 to your computer and use it in GitHub Desktop.
JsUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function JSAssert_print() { | |
var win=window.open("","_blank","width=400,height=300,toolbar=no,scrollbars=yes"); | |
win.document.writeln("<TITLE>JSUnit</TITLE><PRE>"); | |
win.document.writeln(""+this.count+" test(s): "+this.done+" ok, "+this.failed+" failed\n---"); | |
win.document.writeln(this.text); | |
win.document.close(); | |
} | |
function JSAssert_add(f, t) { | |
this.count++; | |
if(f) { | |
if(this.printall) this.text+=t+": done\n"; | |
this.done++; | |
} else { | |
this.text+=t+": failed condition\n"; | |
this.failed++; | |
} | |
} | |
function JSAssert(printall) { | |
this.printall=printall; | |
this.count=0; | |
this.failed=0; | |
this.done=0; | |
this.text=""; | |
this.add=JSAssert_add; | |
this.print=JSAssert_print; | |
} | |
function JSTestSuite_add(func) { | |
eval("this.func"+this.count+"=func"); | |
this.count++; | |
} | |
function JSTestSuite_run(printall) { | |
this.assert=new JSAssert(printall); | |
for(var i=0;i<this.count;i++) eval("this.func"+i+"()"); | |
this.assert.print(); | |
this.assert=null; | |
} | |
function JSTestSuite() { | |
this.assert=null; | |
this.count=0; | |
this.add=JSTestSuite_add; | |
this.run=JSTestSuite_run; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment