Activate your free membership today | Log-in

Wednesday, September 3rd, 2008

QUnit: A simple look at the jQuery unit test framework

Category: JavaScript, jQuery, Testing

<p>

Chad Myers has a simple look at GUnit, the jQuery based unit test framework. His article explains how to get going, and walks through a test like this:

JAVASCRIPT:
  1.  
  2. module("Show and Hide");
  3.  
  4. test("should hide the element when hide is called", function(){
  5.  
  6.     $("#testDiv").hide();
  7.  
  8.     // actual, expected
  9.     equals($("#testDiv").css("display"), "none", "The element should be hidden");
  10. });
  11.  
  12. test("should show the element when show is called", function(){
  13.  
  14.     // Arrange
  15.     $("#testDiv").css("display", "none");
  16.    
  17.     // Act
  18.     $("#testDiv").show();
  19.  
  20.     // Assert
  21.     // actual, expected
  22.     equals($("#testDiv").css("display"), "block", "The element should be visible");
  23. });
  24.  

Related Content:

Posted by Dion Almaer at 5:12 am
2 Comments

++++-
4.4 rating from 14 votes

2 Comments »

Comments feed TrackBack URI

xor,
.
Which would you choose if you were starting a project today? jqUnit?

Comment by Nosredna — September 3, 2008

I don’t think there is noticeable difference for *new* project. If you don’t have old tests written in JSUnit, then both are the same for you. At the same time, both libraries are not that well documented, so there could be some subtle differences (I didn’t have time to compare code closely).

Comment by xor — September 3, 2008

Leave a comment

You must be logged in to post a comment.