mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-24 07:34:11 +00:00
Tests: Extract createStubMap
Minimal mw.Map stub that covers get with key and a default value Change-Id: I15d60d78ed86747a94f371fd3df400906f0c6dab
This commit is contained in:
parent
d662bc62b2
commit
35c7068fbe
|
@ -1,13 +1,6 @@
|
|||
var mw = mediaWiki,
|
||||
createSchema = require( '../../src/schema' );
|
||||
|
||||
function createStubMap() {
|
||||
var m = new Map(); /* global Map */
|
||||
m.get = function ( key, def ) {
|
||||
return Map.prototype.get.call( m, key ) || def;
|
||||
};
|
||||
return m;
|
||||
}
|
||||
createSchema = require( '../../src/schema' ),
|
||||
createStubMap = require( './stubs' ).createStubMap;
|
||||
|
||||
QUnit.module( 'ext.popups/schema', {
|
||||
setup: function () {
|
||||
|
|
|
@ -15,3 +15,22 @@ exports.createStubUser = function createStubUser( isAnon ) {
|
|||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a **minimal** stub that can be used in place of an `mw.Map`
|
||||
* instance.
|
||||
*
|
||||
* @return {mw.Map}
|
||||
*/
|
||||
exports.createStubMap = function createStubMap() {
|
||||
var m = new Map(); /* global Map */
|
||||
m.get = function ( key, fallback ) {
|
||||
fallback = arguments.length > 1 ? fallback : null;
|
||||
if ( typeof key === 'string' ) {
|
||||
return m.has( key ) ? Map.prototype.get.call( m, key ) : fallback;
|
||||
}
|
||||
// Invalid selection key
|
||||
return null;
|
||||
};
|
||||
return m;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue