-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.js
49 lines (36 loc) · 1.62 KB
/
solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 35: Symbol.for - retrieves or creates a runtime-wide symbol (solution)
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Symbol.for` for registering Symbols globally', function() {
it('creates a new symbol (check via `typeof`)', function() {
const symbolType = typeof Symbol.for('symbol name');
assert.equal(symbolType, 'symbol');
});
it('stores the symbol in a runtime-wide registry and retrieves it from it', function() {
const sym = Symbol.for('new symbol');
const sym1 = Symbol.for('new symbol');
assert.equal(sym, sym1);
});
it('is different to `Symbol()` which creates a symbol every time and does not store it', function() {
var globalSymbol = Symbol.for('new symbol');
var localSymbol = Symbol('new symbol');
assert.notEqual(globalSymbol, localSymbol);
});
describe('`.toString()` on a Symbol', function() {
const localSymbol = Symbol('new symbol');
const symbolFromRegistry = Symbol.for('new symbol');
it('also contains the key given to `Symbol.for()`', function() {
const description = localSymbol.toString();
assert.equal(description, 'Symbol(new symbol)');
});
describe('NOTE: the description of two different symbols', function() {
it('might be the same', function() {
const localDescription = localSymbol.toString();
const fromRegistryDescription = ''+symbolFromRegistry.toString();
assert.equal(localDescription, fromRegistryDescription);
});
it('but the symbols are not the same!', function() {
assert.notEqual(localSymbol, symbolFromRegistry);
});
});
});
});