Manual:JavaScript unit testing/QUnit guidelines

MediaWiki core
Core test suites need to be added to the registration of the  module. Do so in QUnitTestResources.php (in ./tests/qunit/).

So if you created a test suite for, then that test suite should be stored in ./tests/qunit/suites/resources/mediawiki/mediawiki.foobar.test. Then you would add that file path to the "scripts" array. And, unless already, add the  module as a dependency (since that module must be loaded before the test suite can run).

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

Guidelines for Qunit tests
Use equal instead of ok as much as possible. ok is not useful in most unit testing because it makes you have to do the comparison inline. Which means the value given to ok is only the end result, not the expected/result values themselves. Which means in case of a failure, ok can only say "Passed" or "Failed", whereas equal (having both values), can output useful debug information. This is especially important when working with test reports generated externally (eg. through TestSwarm) in which are the test report is all you have.

The #qunit-fixture element can be used to provide and manipulate test markup, and will be automatically reset after each test (see QUnit.reset). The element is styled with position:absolute; top:-10000px; left:-10000; - with these, it won't be obstructing the result, without affecting code the relies on the affected elements to be visible (instead of display:none).