Merge branch 'master' of github.com:danvk/dygraphs
authorDan Vanderkam <dan@dygraphs.com>
Tue, 2 Aug 2011 04:25:37 +0000 (07:25 +0300)
committerDan Vanderkam <dan@dygraphs.com>
Tue, 2 Aug 2011 04:25:37 +0000 (07:25 +0300)
auto_tests/misc/fake-jstestdriver.js
auto_tests/misc/local.html

index 4397741..702f3d4 100644 (file)
@@ -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;
index 0d10bb6..428e444 100644 (file)
@@ -69,7 +69,8 @@
   HTML file. To run a test, open a Javascript console and execute, for
   instance,<br>
   <code>tc = new SimpleDrawingTestCase() ;<br>
-    tc.runTest("testDrawSimpleRangePlusOne")</code>
+    tc.runTest("testDrawSimpleRangePlusOne")</code> (execution method #1, by string) </br>
+  <code>tc.runTest(tc.testDrawSimpleRangePlusOne)</code> (execution method #2, by function reference)
 
   <p>Alternatively you can use query args: <ul>
   <li>testCase - for the name of the test case