Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

Added raises assertion, reusing some of kennsnyder's code.
authorjzaefferer <joern.zaefferer@gmail.com>
Mon, 26 Jul 2010 17:42:30 +0000 (19:42 +0200)
committerjzaefferer <joern.zaefferer@gmail.com>
Mon, 26 Jul 2010 17:42:30 +0000 (19:42 +0200)
qunit/qunit.js
test/same.js
test/test.js

index 48696e3..42cdb0a 100644 (file)
@@ -285,7 +285,17 @@ var QUnit = {
        notStrictEqual: function(actual, expected, message) {
                push(expected !== actual, actual, expected, message);
        },
-       
+
+       raises: function(fn,  message) {
+               try {
+                       fn();
+                       ok( false, message );
+               }
+               catch (e) {
+                       ok( true, message );
+               }
+       },
+
        start: function() {
                // A slight delay, to avoid any current callbacks
                if ( window.setTimeout ) {
index 8f1b563..92940dc 100644 (file)
@@ -1406,7 +1406,6 @@ test('mixed object/array with references to self wont loop', function(){
     equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object/array (unambigous test)");
 });
 
-
 test("Test that must be done at the end because they extend some primitive's prototype", function() {
     // Try that a function looks like our regular expression.
     // This tests if we check that a and b are really both instance of RegExp
@@ -1421,3 +1420,20 @@ test("Test that must be done at the end because they extend some primitive's pro
     equals(QUnit.equiv(function () {}, re), false, "Same conversely, but ensures that function and regexp are distinct because their constructor are different");
 });
 
+module("testers");
+
+test("raises", function() {
+       function thrower1() {
+               throw 'Errored!';
+       }
+       function thrower2() {
+               throw new TypeError("Type!");
+       }
+       function thrower3() {
+               var e = {message:"Custom!"};
+               throw e;
+       }
+       raises(thrower1, 'Errored!', 'throwing string');
+       raises(thrower2, 'Type!', 'throwing TypeError instance');
+       raises(thrower3, 'Custom!', 'throwing custom object');
+});
index 4b88f18..aa06d9b 100644 (file)
@@ -211,3 +211,19 @@ test("basics", function() {
                actual = QUnit.diff("the quick brown fox jumped over", "the quick fox jumps over").replace(/^\s+/, '').replace(/\s+$/, '');
        equal(actual, expected); 
 });
+
+module("assertions");
+test("raises", function() {
+       function thrower1() {
+               throw 'Errored!';
+       }
+       function thrower2() {
+               throw new TypeError("Type!");
+       }
+       function thrower3() {
+               throw {message:"Custom!"};
+       }
+       raises(thrower1, 'Errored!', 'throwing string');
+       raises(thrower2, 'Type!', 'throwing TypeError instance');
+       raises(thrower3, 'Custom!', 'throwing custom object');
+});

Hosting is provided AltSPAHow to use Git
Please direct any questions on jabber alex.wolf@jabber.ru

Valid HTML 4.0 Transitional Valid CSS!

Designer Alexander Wolf