Last active
February 26, 2016 22:47
-
-
Save nmccready/689202b1624fc0ce4590 to your computer and use it in GitHub Desktop.
es6MapTdd.js http://es6katas.org/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 44: Map - basics | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('`Map` is a key/value map', function(){ | |
it('`Map` is a new global constructor function', function() { | |
assert.equal(typeof Map, 'function'); | |
}); | |
it('provides `new Map().set()` to add key+value pair, `get()` to read it by key', function() { | |
let map = new Map(); | |
map.set('key', 'value'); | |
const value = map.get('key'); | |
assert.equal(value, 'value'); | |
}); | |
it('`has()` tells if map has the given key', function() { | |
let map = new Map(); | |
map.set('key', 'value'); | |
const hasIt = map.has('key'); | |
assert.equal(hasIt, true); | |
}); | |
it('a map is iterable', function() { | |
let map = new Map(); | |
map.set('1', 'one'); | |
map.set('2', 'two'); | |
const mapAsArray = Array.from(map); // hint: kata #29 http://tddbin.com/#?kata=es6/language/array-api/from | |
assert.deepEqual(mapAsArray, [['1', 'one'], ['2', 'two']]); | |
}); | |
it('complex types can be keys', function() { | |
const obj = {x: 1}; | |
const otherObj = {x: 1}; | |
let map = new Map(); | |
map.set(obj, ''); | |
map.set(otherObj, 'crap'); | |
assert.equal(map.has(otherObj), true); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment