Guest User

Untitled

a guest
Jan 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. // 54: Object - is
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3. // Follow the hints of the failure messages!
  4.  
  5. describe('`Object.is()` determines whether two values are the same', function(){
  6. describe('scalar values', function() {
  7. it('1 is the same as 1', function() {
  8. const areSame = Object.is(1, 1);
  9. assert(areSame);
  10. });
  11. it('int 1 is different to string "1"', function() {
  12. const areSame = Object.is(1, '1');
  13. assert(areSame === false);
  14. });
  15. it('strings just have to match', function() {
  16. const areSame = Object.is('one', 'one');
  17. assert(areSame);
  18. });
  19. it('+0 is not the same as -0', function() {
  20. const areSame = 0;
  21. assert.equal(Object.is(+0, -0), areSame);
  22. });
  23. it('NaN is the same as NaN', function() {
  24. const number = NaN;
  25. assert.equal(Object.is(NaN, number), true);
  26. });
  27. });
  28. describe('coercion, as in `==` and `===`, does NOT apply', function() {
  29. it('+0 != -0', function() {
  30. const coerced = +0 != -0;
  31. const isSame = Object.is(+0, -0);
  32. assert.equal(isSame, coerced);
  33. });
  34. it('empty string and `false` are not the same', function() {
  35. const emptyString = 'false';
  36. const isSame = Object.is(emptyString, false);
  37. assert.equal(isSame, emptyString == false);
  38. });
  39. it('NaN', function() {
  40. const coerced = NaN != NaN;
  41. const isSame = Object.is(NaN, NaN);
  42. assert.equal(isSame, coerced);
  43. });
  44. it('NaN 0/0', function() {
  45. const isSame = Object.is(NaN, 0/0);
  46. assert.equal(isSame, true);
  47. });
  48. });
  49. describe('complex values', function() {
  50. it('`{}` is just not the same as `{}`', function() {
  51. const areSame = false;
  52. assert(Object.is({}, {}) === areSame);
  53. });
  54. it('Map', function() {
  55. let map1 = new Map([[1, 'one']]);
  56. let map2 = new Map([[1, 'one']]);
  57. const areSame = Object.is(map1, map2);
  58. assert.equal(areSame, false);
  59. });
  60. });
  61. });
Add Comment
Please, Sign In to add comment