Created
January 3, 2018 06:04
-
-
Save hanmd82/62f2f907f30d7418114d5b74746b9a2a to your computer and use it in GitHub Desktop.
ES6 katas for Objects - 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
// 54: Object - is | |
describe('`Object.is()` determines whether two values are the same', function(){ | |
describe('scalar values', function() { | |
it('1 is the same as 1', function() { | |
const areSame = Object.is(1, 1); | |
assert.equal(areSame, true); | |
}); | |
it('int 1 is different to string "1"', function() { | |
const areSame = Object.is(1, '1'); | |
assert.equal(areSame, false); | |
}); | |
it('strings just have to match', function() { | |
const areSame = Object.is('one', 'one'); | |
assert.equal(areSame, true); | |
}); | |
it('+0 is not the same as -0', function() { | |
const areSame = false; | |
assert.equal(Object.is(+0, -0), areSame); | |
}); | |
it('NaN is the same as NaN', function() { | |
const number = NaN; | |
assert.equal(Object.is(NaN, number), true); | |
}); | |
}); | |
describe('coercion, as in `==` and `===`, does NOT apply', function() { | |
it('+0 != -0', function() { | |
const coerced = +0 != -0; | |
const isSame = Object.is(+0, -0); | |
assert.equal(isSame, coerced); | |
}); | |
it('empty string and `false` are not the same', function() { | |
const emptyString = 'false'; | |
const isSame = Object.is(emptyString, false); | |
assert.equal(isSame, emptyString == false); | |
}); | |
it('NaN', function() { | |
const coerced = NaN == NaN; | |
const isSame = Object.is(NaN, !NaN); | |
assert.equal(isSame, coerced); | |
}); | |
it('NaN 0/0', function() { | |
const isSame = Object.is(NaN, 0/0); | |
assert.equal(isSame, true); | |
}); | |
}); | |
describe('complex values', function() { | |
it('`{}` is just not the same as `{}`', function() { | |
const areSame = false; | |
assert.equal(Object.is({}, {}), areSame); | |
}); | |
it('Map', function() { | |
let map1 = new Map([[1, 'one']]); | |
let map2 = new Map([[1, 'one']]); | |
const areSame = Object.is(map1, map2); | |
assert.equal(areSame, false); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment