Manual:JavaScript unit testing

MediaWiki uses QUnit to unit test its JavaScript code base.

The unit tests for MediaWiki core are located in the  directory.

Run the tests
Ensure is set to.

In a browser
Open in a browser to run the tests.

Options:
 * Check for Globals: Core URL parameter of QUnit.
 * No try-catch: Core URL parameter of QUnit.
 * Enable ResourceLoaderDebug: Toggle ResourceLoader debug mode.
 * Module: Select a module from the list to immediately run it.

From the command line
Use  from the MediaWiki core directory to run QUnit tests from the command-line in Chrome and aggregate the results.

Run tests before committing
Make it a habit to run unit tests before committing and submitting your changes to Gerrit.

Write unit tests
Always write unit tests for new functionality. We're also looking to expand our unit test coverage of already existing modules in the MediaWiki JavaScript library.

Write a unit test

 * TODO: Incomplete


 * The file should be named after the module (or file) it is testing. E.g.  covers the   module.


 * Inside the test suite should be one, and only one, call to  with the module name.

MediaWiki core
Test suites are added to the registration of the  module in.

Tests are organised into a directory structure that matches the directory structure of the code being tested. For example: The unit test for  can be found at.

Example:

Extensions
Extensions register their QUnit tests as a module. See Manual:Hooks/ResourceLoaderTestModules for more details.