Extension:MobileFrontend/Writing QUnit tests

From mediawiki.org

Setting up your test environment[edit]

Put this in LocalSettings.php

$wgEnableJavaScriptTest = true;

Now try running the existing tests.

  1. On the command line simply by running `make qunit`
  2. Visit Special:JavaScriptTest/QUnit in the mobile skin or desktop skin.

Caveat: Depending on whether you are in mobile mode or desktop mode different tests will run!

If they are green great let's write a new test!

Adding your test file[edit]

In mobile to add a test navigate to the tests/qunit folder All files here are laid out as they are in the javascripts folder and have the same filename only prefixed with test_

e.g. A file in javascripts/common called Xyz.js will have a corresponding test in tests/qunit/common/test_Xyz.js

Add the following code into your new test file:

( function ( M, $ ) {
	QUnit.module( 'MobileFrontend test' );

	QUnit.test( 'Never passing test', function( assert ) {
		assert.strictEqual( false, true, 'Test false is the same as true. What can possibly go wrong?' );
	} );

}( mw.mobileFrontend, jQuery ) );

Now run the test. It should fail. If so yeyy.

Writing your test[edit]

QUnit is pretty basic once you get the hang of it. Manual:JavaScript_unit_testing/QUnit_guidelines is a good jumping off point.