Help:Using QUnit
Writing testable code | |
---|---|
JavaScript and jQuery | |
Keywords | |
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(
'tests/qunit/ext.smw.test.js',
...
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]
[a.7] http://qunitjs.com/cookbook/
[a.8] http://benalman.com/talks/unit-testing-qunit.html
Namespace[edit]
Try to avoid polluting the global $/window namespace [a.2, a.3, a.4] and instead use smw/srf.
[a.2] https://gist.github.com/hallettj/64478
[a.3] http://yuiblog.com/blog/2007/06/12/module-pattern/
[a.4] http://www.javascripttoolbox.com/bestpractices/#namespace
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]
|
|