"deepmerge": "1.3.2",
"eslint": "4.9.0",
"eslint-config-wikimedia": "0.5.0",
+ "eslint-plugin-qunit": "3.2.1",
"grunt": "1.0.1",
"grunt-banana-checker": "0.6.0",
"grunt-contrib-copy": "1.0.0",
{
- "extends": "../../.eslintrc.json",
+ "extends": [
+ "../../.eslintrc.json",
+ "plugin:qunit/recommended",
+ "plugin:qunit/two"
+ ],
"env": {
"qunit": true
},
"rules": {
"operator-linebreak": 0,
"quote-props": [ "error", "as-needed" ],
- "valid-jsdoc": 0
- }
+ "valid-jsdoc": 0,
+ "qunit/require-expect": 0,
+ "qunit/resolve-async": 0
+ },
+ "plugins": [ "qunit" ]
}
* Configuration
*/
- // For each test() that is asynchronous, allow this time to pass before
+ // For each test that is asynchronous, allow this time to pass before
// killing the test and assuming timeout failure.
QUnit.config.testTimeout = 60 * 1000;
}() );
/**
- * Reset mw.config and others to a fresh copy of the live config for each test(),
+ * Reset mw.config and others to a fresh copy of the live config for each test,
* and restore it back to the live one afterwards.
*
* @param {Object} [localEnv]
} );
QUnit.module( 'testrunner-each-compat', {
+ // eslint-disable-next-line qunit/no-setup-teardown
setup: function () {
this.mwHtmlLive = mw.html;
},
+ // eslint-disable-next-line qunit/no-setup-teardown
teardown: function () {
mw.html = this.mwHtmlLive;
}
function among( actual, expected, message ) {
if ( Array.isArray( expected ) ) {
- assert.ok( expected.indexOf( actual ) !== -1, message + ' (got ' + actual + '; expected one of ' + expected.join( ', ' ) + ')' );
+ assert.equal( expected.indexOf( actual ) !== -1, true, message + ' (got ' + actual + '; expected one of ' + expected.join( ', ' ) + ')' );
} else {
assert.equal( actual, expected, message );
}
.then( function ( token ) {
assert.ok( token.length, 'Got a token' );
}, function ( err ) {
- assert.equal( '', err, 'API error' );
+ assert.equal( err, '', 'API error' );
} )
.then( function () {
assert.equal( test.server.requests.length, 0, 'Requests made' );
} );
QUnit.module( 'mediawiki.api (2)', {
- setup: function () {
+ beforeEach: function () {
var self = this,
requests = this.requests = [];
this.api = new mw.Api();
b: 2
} );
this.api.abort();
- assert.ok( this.requests.length === 2, 'Check both requests triggered' );
+ assert.equal( this.requests.length, 2, 'Check both requests triggered' );
this.requests.forEach( function ( request, i ) {
assert.ok( request.abort.calledOnce, 'abort request number ' + i );
} );
QUnit.test( 'getVersion', function ( assert ) {
var uriProcessor = new mw.rcfilters.UriProcessor( new mw.rcfilters.dm.FiltersViewModel() );
- assert.ok(
+ assert.equal(
uriProcessor.getVersion( { param1: 'foo', urlversion: '2' } ),
2,
'Retrieving the version from the URI query'
);
- assert.ok(
+ assert.equal(
uriProcessor.getVersion( { param1: 'foo' } ),
1,
'Getting version 1 if no version is specified'
foo: 'quux',
pif: 'paf'
} );
- assert.ok( uri.toString().indexOf( 'foo=quux' ) >= 0, 'extend query arguments' );
- assert.ok( uri.toString().indexOf( 'foo=bar' ) === -1, 'extend query arguments' );
- assert.ok( uri.toString().indexOf( 'pif=paf' ) >= 0, 'extend query arguments' );
+ assert.equal( uri.toString().indexOf( 'foo=quux' ) !== -1, true, 'extend query arguments' );
+ assert.equal( uri.toString().indexOf( 'foo=bar' ) !== -1, false, 'extend query arguments' );
+ assert.equal( uri.toString().indexOf( 'pif=paf' ) !== -1, true, 'extend query arguments' );
} );
QUnit.test( '.getQueryString()', function ( assert ) {
// Verify parts and total length instead of entire string because order
// of iteration can vary.
- assert.ok( uri.toString().indexOf( 'm=bar' ), 'toString preserves other values' );
- assert.ok( uri.toString().indexOf( 'n=x&n=y&n=z' ), 'toString parameter includes all values of an array query parameter' );
+ assert.equal( uri.toString().indexOf( 'm=bar' ) !== -1, true, 'toString preserves other values' );
+ assert.equal( uri.toString().indexOf( 'n=x&n=y&n=z' ) !== -1, true, 'toString parameter includes all values of an array query parameter' );
assert.equal( uri.toString().length, 'http://www.example.com/dir/?m=bar&n=x&n=y&n=z'.length, 'toString matches expected string' );
uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
// Verify parts and total length instead of entire string because order
// of iteration can vary.
- assert.ok( uri.toString().indexOf( 'm=foo&m=bar' ) >= 0, 'toString preserves other values' );
- assert.ok( uri.toString().indexOf( 'n=x&n=y&n=z' ) >= 0, 'toString parameter includes all values of an array query parameter' );
+ assert.equal( uri.toString().indexOf( 'm=foo&m=bar' ) !== -1, true, 'toString preserves other values' );
+ assert.equal( uri.toString().indexOf( 'n=x&n=y&n=z' ) !== -1, true, 'toString parameter includes all values of an array query parameter' );
assert.equal( uri.toString().length, 'http://www.example.com/dir/?m=foo&m=bar&n=x&n=y&n=z'.length, 'toString matches expected string' );
// Remove query values
assert.equal( uri.getHostPort(), 'www.example.com:81', 'hostport equal to host:port' );
queryString = uri.getQueryString();
- assert.ok( queryString.indexOf( 'q1=0' ) >= 0, 'query param with numbers' );
- assert.ok( queryString.indexOf( 'test1' ) >= 0, 'query param with null value is included' );
- assert.ok( queryString.indexOf( 'test1=' ) === -1, 'query param with null value does not generate equals sign' );
- assert.ok( queryString.indexOf( 'test2=value+%28escaped%29' ) >= 0, 'query param is url escaped' );
+ assert.equal( queryString.indexOf( 'q1=0' ) !== -1, true, 'query param with numbers' );
+ assert.equal( queryString.indexOf( 'test1' ) !== -1, true, 'query param with null value is included' );
+ assert.equal( queryString.indexOf( 'test1=' ) !== -1, false, 'query param with null value does not generate equals sign' );
+ assert.equal( queryString.indexOf( 'test2=value+%28escaped%29' ) !== -1, true, 'query param is url escaped' );
relativePath = uri.getRelativePath();
assert.ok( relativePath.indexOf( uri.path ) >= 0, 'path in relative path' );
};
assert.equal(
- 'A',
getBucket( experiment, token ),
+ 'A',
'It returns the bucket if only one is defined.'
);
experiment.enabled = false;
assert.equal(
- 'control',
getBucket( experiment, token ),
+ 'control',
'It returns "control" if the experiment is disabled.'
);
experiment.buckets = {};
assert.equal(
- 'control',
getBucket( experiment, token ),
+ 'control',
'It returns "control" if the experiment doesn\'t have any buckets.'
);
} );
// Not that we need this. ;)
// This fails on IE 6-8
// Works on IE 9, Firefox 6, Chrome 14
- QUnit.test( 'Keyword workaround: "if" as variable name using Unicode escapes', function ( assert ) {
+ ...( 'Keyword workaround: "if" as variable name using Unicode escapes', function ( assert ) {
var orig = "another token";
\u0069\u0066 = orig;
assert.deepEqual( \u0069\u0066, orig, '\\u0069\\u0066' );
// Not that we need this. ;)
// This fails on IE 6-9
// Works on Firefox 6, Chrome 14
- QUnit.test( 'Keyword workaround: "if" as member variable name using Unicode escapes', function ( assert ) {
+ ...( 'Keyword workaround: "if" as member variable name using Unicode escapes', function ( assert ) {
var orig = "another token";
var foo = {};
foo.\u0069\u0066 = orig;
);
/**
- * The sync style load test (for @import). This is, in a way, also an open bug for
+ * The sync style load test, for @import. This is, in a way, also an open bug for
* ResourceLoader ("execute js after styles are loaded"), but browsers don't offer a
* way to get a callback from when a stylesheet is loaded (that is, including any
* `@import` rules inside). To work around this, we'll have a little time loop to check
try {
assert.strictEqual( cb.later(), 'Defined.', 'require works asynchrously in debug mode' );
} catch ( e ) {
- assert.equal( null, String( e ), 'require works asynchrously in debug mode' );
+ assert.equal( String( e ), null, 'require works asynchrously in debug mode' );
}
} );
} );
( function ( mw ) {
QUnit.module( 'mediawiki.template.mustache', {
- setup: function () {
+ beforeEach: function () {
// Stub register some templates
this.sandbox.stub( mw.templates, 'get' ).returns( {
'test_greeting.mustache': '<div>{{foo}}{{>suffix}}</div>',
( function ( mw ) {
QUnit.module( 'mediawiki.template', {
- setup: function () {
+ beforeEach: function () {
var abcCompiler = {
compile: function () {
return 'abc default compiler';
// Interacting with globals
conf.set( 'globalMapChecker', 'Hi' );
- assert.ok( ( 'globalMapChecker' in window ) === false, 'Map does not its store values in the window object by default' );
+ assert.equal( 'globalMapChecker' in window, false, 'Map does not its store values in the window object by default' );
globalConf = new mw.Map( true );
globalConf.set( 'anotherGlobalMapChecker', 'Hello' );