Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. // 35: Symbol.for - retrieves or creates a runtime-wide symbol
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3. // Follow the hints of the failure messages!
  4.  
  5. describe('`Symbol.for` for registering Symbols globally', function() {
  6. it('creates a new symbol (check via `typeof`)', function() {
  7. const symbolType = typeof Symbol.for('symbol name');
  8. assert.equal(symbolType, 'symbol');
  9. });
  10. it('stores the symbol in a runtime-wide registry and retrieves it from there', function() {
  11. const sym = Symbol.for('new symbol');
  12. const sym1 = Symbol.for('new symbol');
  13. assert.equal(sym, sym1);
  14. });
  15. it('is different to `Symbol()` which creates a symbol every time and does not store it', function() {
  16. var globalSymbol = Symbol.for('new symbol');
  17. var localSymbol = Symbol.for('new symbol1');
  18. assert.notEqual(globalSymbol, localSymbol);
  19. });
  20. describe('`.toString()` on a Symbol', function() {
  21. it('also contains the key given to `Symbol.for()`', function() {
  22. const description = Symbol('new symbol').toString();
  23. assert.equal(description, 'Symbol(new symbol)');
  24. });
  25. describe('NOTE: the description of two different symbols', function() {
  26. it('might be the same', function() {
  27. const symbol1AsString = Symbol('new symbol').toString();
  28. const symbol2AsString = Symbol.for('new symbol').toString();
  29. assert.equal(symbol1AsString, symbol2AsString);
  30. });
  31. it('but the symbols are not the same!', function() {
  32. const symbol1 = Symbol.for('new symbol');
  33. const symbol2 = Symbol.for('new symbol2');
  34. assert.notEqual(symbol1, symbol2);
  35. });
  36. });
  37. });
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement