Help:Using QUnit

(Redirected from Help:Using QUnit)
Writing testable code
JavaScript and jQuery
Tests · Testable code · QUnit
Table of Contents

Semantic MediaWiki functionality relies in some part on JavaScript and jQuery and with an increasingly diverse browser environment (mobile and desktop browsers) different scopes putting constraints on provided functionality therefore testing across different platforms and browsers becomes vital to ensure similar user experiences and behaviour.

Register unit tests[edit]

Hooks/ResourceLoaderTestModules is used to register available tests.(See also SemanticMediawiki.hooks.php and tests/qunit folder.

public static function registerQUnitTests( array &$testModules, ResourceLoader &$resourceLoader ){
	$testModules['qunit']['ext.semanticMediaWiki'] = array(
		'scripts' => array(

Ensuring a continuous integration for JavaScript and jQuery, MediaWiki provides a JavaScript unit testing environment with 1.19 using the QUnit testing suite. A how-to for SMW specific task has yet to be decided but general information can be found at SMW JavaScript Testing with QUnit.

Best practices[edit]




Try to avoid polluting the global $/window namespace [a.2, a.3, a.4] and instead use smw/srf.




Module pattern[edit]

Testing environment[edit]

If $wgEnableJavaScriptTest is enabled and tests have been successfully registered, those can be accessed via Special:JavaScriptTest/qunit. If you want to run only a specific module, you can add Special:JavaScriptTest/qunit?module=<module name> (e.g. Special:JavaScriptTest/qunit?module=ext.smw)

See also[edit]

  • Firebug console debugger, sometimes it is just enough to use console.profile(); or console.log(); to find miscellaneous software code (a sum-up can be found here).
  • Tutorial on methods to increase jQuery readability and performance