Extension:MobileFrontend/Writing QUnit tests
Setting up your test environment
editPut this in LocalSettings.php
$wgEnableJavaScriptTest = true;
Now try running the existing tests.
- On the command line simply by running `make qunit`
- 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
editIn 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
editQUnit is pretty basic once you get the hang of it. Manual:JavaScript_unit_testing/QUnit_guidelines is a good jumping off point.