Unit Test

Dependencies

  • jQuery, Getting Started

  • Test framework

    wget http://code.jquery.com/qunit/git/qunit.css
    wget http://code.jquery.com/qunit/git/qunit.js
    

Issues

equal fails when objects are the same

Use deepEqual (deepEqual) to check the contents of an object (rather than if the object is the same):

test("a test", function() {
  var actual = {a: 1};
  equal(actual, {a: 1}, "must fail, same content, but different object, not handled by equals");
  deepEqual(actual, {a: "1"}, "must fail, expected value is a string, actual a number");
  deepEqual(actual, {a: 1}, "must pass, same content, but different object);
});

Sample

sample/javascript/jquery/sample_unittest/