Jhernandez has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/340339 )

Change subject: Tests: Extract createStubMap
......................................................................

Tests: Extract createStubMap

Minimal mw.Map stub that covers get with key and a default value

Change-Id: I15d60d78ed86747a94f371fd3df400906f0c6dab
---
M tests/node-qunit/schema.test.js
M tests/node-qunit/stubs.js
2 files changed, 21 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups 
refs/changes/39/340339/1

diff --git a/tests/node-qunit/schema.test.js b/tests/node-qunit/schema.test.js
index 901c1e4..757e4ca 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 8c10b79..048e1ee 100644
--- a/tests/node-qunit/stubs.js
+++ b/tests/node-qunit/stubs.js
@@ -15,3 +15,22 @@
                }
        };
 };
+
+/**
+ * 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;
+};

-- 
To view, visit https://gerrit.wikimedia.org/r/340339
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I15d60d78ed86747a94f371fd3df400906f0c6dab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <jhernan...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to