Appendix B. How jQuery UI tests jQuery UI

 

To verify that the various features of jQuery UI work as intended, the library has a series of unit tests that run in all the library’s supported browsers. The tests themselves are written using the QUnit testing library. Because several excellent QUnit tutorials are online (http://qunitjs.com/cookbook/ is a particularly good one), I won’t give one here. Instead, I’ll show how jQuery UI tests its own widgets, using examples directly from the jQuery UI source code. Hopefully, looking at how jQuery UI tests its own widgets will help you approach testing yours.

B.1. Testing options

jQuery UI attempts to test every potential value of every option for every widget. Although the test coverage isn’t perfect, the majority of options have tests to verify their behavior.

Note

The $( "#spin" ) call selects an <input id="spin"> element in the <div id="qunit-fixture">. If you’re not familiar with QUnit, the fixture <div> is a place to put markup to use during the tests. QUnit resets the markup in the fixture to its initial state before each test—ensuring changes made in one test don’t affect others.

Here’s the spinner widget’s tests for its max option:

B.2. Testing methods

B.3. Testing events