📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials jQuery in Practice Testing jQuery Code

Testing jQuery Code

5 min read
Test jQuery plugins with QUnit. Write HTML in the #qunit-fixture div, apply your plugin, then assert the DOM result. QUnit resets the fixture between tests to prevent state leakage between individual tests.

Testing with QUnit

<script src="qunit.js"></script>

QUnit.test('highlight plugin', function(assert) {
  $('#fixture').highlight();
  assert.ok(
    $('#fixture').css('background') !== '',
    'Background set'
  );
});