Bug 877178 - Add an exception checking method to SimpleTest, r=robcee
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Sat, 01 Jun 2013 15:33:03 +0200
changeset 140822 20dbb98fcac2eecbb5cfeea3de26966773aa3efa
parent 140821 3ecac4bcc92e6df394f6da25dcfd56fbc41e130b
child 140823 df3fbbf0b7fe4316bba0b6cbdd4ea904e75cf06b
push id3911
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 20:17:26 +0000
treeherdermozilla-aurora@7e26ca8db92b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobcee
bugs877178
milestone24.0a1
Bug 877178 - Add an exception checking method to SimpleTest, r=robcee
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -255,16 +255,27 @@ SimpleTest.isnot = function (a, b, name)
  * Roughly equivalent to ok(a===b, name)
 **/
 SimpleTest.ise = function (a, b, name) {
     var pass = (a === b);
     var diag = pass ? "" : "got " + repr(a) + ", strictly expected " + repr(b)
     SimpleTest.ok(pass, name, diag);
 };
 
+/**
+ * Check that the function call throws an exception.
+ */
+SimpleTest.doesThrow = function(fn, name) {
+    var gotException = false;
+    try {
+      fn();
+    } catch (ex) { gotException = true; }
+    ok(gotException, name);
+};
+
 //  --------------- Test.Builder/Test.More todo() -----------------
 
 SimpleTest.todo = function(condition, name, diag) {
     var test = {'result': !!condition, 'name': name, 'diag': diag, todo: true};
     SimpleTest._logResult(test, "TEST-UNEXPECTED-PASS", "TEST-KNOWN-FAIL");
     SimpleTest._tests.push(test);
 };