From: Robert Konigsberg Date: Mon, 1 Aug 2011 20:09:57 +0000 (-0400) Subject: Provide local test execution by function reference, which is much X-Git-Tag: v1.0.0~432^2^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=47c97d86490258703f825f1b50f519b8772380c8;p=dygraphs.git Provide local test execution by function reference, which is much friendlier than existing string-based invocation. --- diff --git a/auto_tests/misc/fake-jstestdriver.js b/auto_tests/misc/fake-jstestdriver.js index 4397741..702f3d4 100644 --- a/auto_tests/misc/fake-jstestdriver.js +++ b/auto_tests/misc/fake-jstestdriver.js @@ -46,10 +46,32 @@ function TestCase(name) { var testCase = function() { return this; }; testCase.prototype.setUp = function() { }; testCase.prototype.tearDown = function() { }; - testCase.prototype.runTest = function(name) { + /** + * name can be a string, which is looked up in this object, or it can be a + * function, in which case it's run. + * + * Examples: + * var tc = new MyTestCase(); + * tc.runTest("testThis"); + * tc.runTest(tc.testThis); + * + * The duplication tc in runTest is irritating, but it plays well with + * Chrome's console completion. + */ + testCase.prototype.runTest = function(func) { try { this.setUp(); - var fn = this[name]; + + var fn = null; + var parameterType = typeof(func); + if (typeof(func) == "function") { + fn = func; + } else if (typeof(func) == "string") { + fn = this[func]; + } else { + fail("can't supply " + typeof(func) + " to runTest"); + } + fn.apply(this, []); this.tearDown(); return true; diff --git a/auto_tests/misc/local.html b/auto_tests/misc/local.html index 0d10bb6..428e444 100644 --- a/auto_tests/misc/local.html +++ b/auto_tests/misc/local.html @@ -69,7 +69,8 @@ HTML file. To run a test, open a Javascript console and execute, for instance,
tc = new SimpleDrawingTestCase() ;
- tc.runTest("testDrawSimpleRangePlusOne")
+ tc.runTest("testDrawSimpleRangePlusOne") (execution method #1, by string)
+ tc.runTest(tc.testDrawSimpleRangePlusOne) (execution method #2, by function reference)

Alternatively you can use query args: