Friday, January 25th, 2008

Sexy JavaScript?

Category: JavaScript, Tip

How can you not post something called Sexy JavaScript?

javascript

  1. // Sexy JavaScript
  2. // runs assertNotNull(iframeElement) in IE, otherwise assertNull(iframeElement)
  3. // taken from test code for http://yura.thinkweb2.com/scripting/contextMenu/
  4.  
  5. testShimExists: function() { with(this) {
  6.   this[Prototype.Browser.IE ? 'assertNotNull' : 'assertNull'](iframeElement);
  7. }},

Posted by Dion Almaer at 1:27 am
7 Comments

++---
2.1 rating from 61 votes

7 Comments »

Comments feed TrackBack URI

i’m definitely no expert in javascript so i was wonddering what assertNotNull is usable for. And apparently, it does not fit in the definition of Agile Development:

The use of ‘assertNotNull’ should be discouraged. Those of you who have been testing for a while will not be as surprised by this statement, but I think it’s worth repeating since I still see many developers who rely too heavily on this– the weakest kind of assertion you can make about your code.

So what’s wrong with ‘assertNotNull’? Put simply, it’s a crutch. If I could vote it off the island, I would. It is used as a way of testing code in a way that adds only a modicum of value. In fact, I’d go so far as to say that if you rely solely on ‘assertNotNull’ in your test methods, you’re probably writing buggy code, and seeing it used in existing test cases should make one question the implementation.

http://blogs.pathf.com/agileajax/2007/12/assertnotnullth.html

Comment by pixeline — January 25, 2008

Nothing is sexier than browser detection in your test suite.

Comment by henrah — January 25, 2008

As someone that is not that familiar with Unit Test I don’t see a whole lot of value in that code, or purpose.

Comment by SiteSmart — January 25, 2008

henrah read my mind, I don’t see the sexiness.

Comment by Tim Cooijmans — January 25, 2008

Oh, I’m confused! Is this a JavaScript code or a Silvia Saint picture?

Comment by andytesti — January 25, 2008

There is a big difference between sexy and crappy.

Comment by crock — January 25, 2008

@pixeline: Keep in mind that what you linked is an opinion piece that deals with Java, not JavaScript. In this case, testing that the shim exists is sufficient; anything further would be verified by functional tests (does the shim adjust when I move the DHTML layer, etc.).

Dion, are you just scouring Pastie for post ideas now? ;-)

Comment by Andrew Dupont — January 25, 2008

Leave a comment

You must be logged in to post a comment.