Wednesday, September 3rd, 2008

QUnit: A simple look at the jQuery unit test framework

Category: JavaScript, jQuery, Testing

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

Posted by Dion Almaer at 5:12 am
2 Comments

++++-
4 rating from 19 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.