Skip to content
This repository has been archived by the owner on Nov 3, 2019. It is now read-only.
/ jquery.stubs Public archive

A jQuery plugin for stubbing jQuery, to make unit testing and TDD less painful.

License

Notifications You must be signed in to change notification settings

half-ogre/jquery.stubs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jquery.stubs

A jQuery plugin for stubbing jQuery, to make unit testing jQuery less painful

How to use jquery.stubs

Let's say you want to unit test the following code:

function preventFormSubmit() {
  $("#theForm").submit(function() {
    return false;
  });
}

With jquery.stubs, your unit test might look like:

test("the preventFormSubmit() method will prevent the form from submitting", function() {
  // arrange
  var actual = null;
  $.stubs.addForSelector("#theForm", function(stub) {
    stub.submit = function(handler) {
      actual = handler();
    }
  });

  // act
  preventFormSubmit();
  
  // assert
  equals(actual, false);
});

You can also stub jQuery functions (like $.ajax()) using $.stubs.addForFunction, and you can remove all stubs with $.stubs.removeAll(). For further examples of how to use jquery.stubs, see its spec.

About

A jQuery plugin for stubbing jQuery, to make unit testing and TDD less painful.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published