assert.strictEqual( conf.set( funky, 'Funky' ), false, 'Map.set returns boolean false if key was invalid (Function)' );
assert.strictEqual( conf.set( arry, 'Arry' ), false, 'Map.set returns boolean false if key was invalid (Array)' );
assert.strictEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set returns boolean false if key was invalid (Number)' );
-
- assert.strictEqual( conf.get( funky ), null, 'Map.get ruturns null if selection was invalid (Function)' );
- assert.strictEqual( conf.get( nummy ), null, 'Map.get ruturns null if selection was invalid (Number)' );
+ assert.strictEqual( conf.set( null, 'Null' ), false, 'Map.set returns false if key is invalid (null)' );
+ assert.strictEqual( conf.set( {}, 'Object' ), false, 'Map.set returns false if key is invalid (plain object)' );
conf.set( String( nummy ), 'I used to be a number' );
+ assert.strictEqual( conf.get( funky ), null, 'Map.get returns null if selection was invalid (Function)' );
+ assert.strictEqual( conf.get( nummy ), null, 'Map.get returns null if selection was invalid (Number)' );
+ assert.propEqual( conf.get( [ nummy ] ), {}, 'Map.get returns null if selection was invalid (multiple)' );
+ assert.strictEqual( conf.get( nummy, false ), false, 'Map.get returns custom fallback for invalid selection' );
+
assert.strictEqual( conf.exists( 'doesNotExist' ), false, 'Map.exists where property does not exist' );
assert.strictEqual( conf.exists( 'undef' ), true, 'Map.exists where value is `undefined`' );
- assert.strictEqual( conf.exists( nummy ), false, 'Map.exists where key is invalid but looks like an existing key' );
+ assert.strictEqual( conf.exists( [ 'undef', 'example' ] ), true, 'Map.exists with multiple keys (all existing)' );
+ assert.strictEqual( conf.exists( [ 'example', 'doesNotExist' ] ), false, 'Map.exists with multiple keys (some non-existing)' );
+ assert.strictEqual( conf.exists( [] ), true, 'Map.exists with no keys' );
+ assert.strictEqual( conf.exists( nummy ), false, 'Map.exists with invalid key that looks like an existing key' );
+ assert.strictEqual( conf.exists( [ nummy ] ), false, 'Map.exists with invalid key that looks like an existing key' );
// Multiple values at once
+ conf = new mw.Map();
someValues = {
foo: 'bar',
lorem: 'ipsum',
notExist: null
}, 'Map.get return includes keys that were not found as null values' );
- // Interacting with globals and accessing the values object
- this.suppressWarnings();
- assert.strictEqual( conf.get(), conf.values, 'Map.get returns the entire values object by reference (if called without arguments)' );
- this.restoreWarnings();
+ assert.propEqual( conf.values, someValues, 'Map.values is an internal object with all values (exposed for convenience)' );
+ assert.propEqual( conf.get(), someValues, 'Map.get() returns an object with all values' );
+ // 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' );