We use JSUnit at work, and I hate its assert methods.

assertEquals(comment, val1, val2);

YUK, the comment first? Coming from a C# background, this is about as ugly as you could imagine. So for eProject I wrote this simple class to get back to the norm.

var Assert = {
“AreEqual”    : function(val1, val2, comment) { assertEquals(comment, val1, val2) },
“AreNotEqual” : function(val1, val2, comment) { assertNotEquals(comment, val1, val2) },
“Fail”        : function(comment) { fail(comment); },
“IsTrue”      : function(val1, comment) { assertTrue(comment, val1); },
“IsFalse”     : function(val1, comment) { assertFalse(comment, val1); },
“IsNull”      : function(val1, comment) { assertNull(comment, val1); },
“IsNotNull”   : function(val1, comment) { assertNotNull(comment, val1); },
“IsNaN”       : function(val1, comment) { assertNaN(comment, val1); },
“IsNotNaN”    : function(val1, comment) { assertNotNaN(comment, val1); },
“IsUndefined” : function(val1, comment) { assertUndefined(comment, val1); },
“IsNotUndefined”: function(val1, comment) { assertNotUndefined(comment, val1); }
};

If you hate it too, then by all means, feel the love of the Assert class.

No comments

Leave a Reply