diff --git a/tests/node-qunit/schema.test.js b/tests/node-qunit/schema.test.js index 901c1e4ed..757e4cabb 100644 --- a/tests/node-qunit/schema.test.js +++ b/tests/node-qunit/schema.test.js @@ -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 () { diff --git a/tests/node-qunit/stubs.js b/tests/node-qunit/stubs.js index 8c10b79c1..048e1ee05 100644 --- a/tests/node-qunit/stubs.js +++ b/tests/node-qunit/stubs.js @@ -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; +};