Projekt

Obecné

Profil

Stáhnout (1.88 KB) Statistiky
| Větev: | Revize:
1
'use strict';
2

    
3
module.exports = function runSymbolTests(t) {
4
	t.equal(typeof Symbol, 'function', 'global Symbol is a function');
5

    
6
	if (typeof Symbol !== 'function') { return false };
7

    
8
	t.notEqual(Symbol(), Symbol(), 'two symbols are not equal');
9

    
10
	/*
11
	t.equal(
12
		Symbol.prototype.toString.call(Symbol('foo')),
13
		Symbol.prototype.toString.call(Symbol('foo')),
14
		'two symbols with the same description stringify the same'
15
	);
16
	*/
17

    
18
	var foo = Symbol('foo');
19

    
20
	/*
21
	t.notEqual(
22
		String(foo),
23
		String(Symbol('bar')),
24
		'two symbols with different descriptions do not stringify the same'
25
	);
26
	*/
27

    
28
	t.equal(typeof Symbol.prototype.toString, 'function', 'Symbol#toString is a function');
29
	// t.equal(String(foo), Symbol.prototype.toString.call(foo), 'Symbol#toString equals String of the same symbol');
30

    
31
	t.equal(typeof Object.getOwnPropertySymbols, 'function', 'Object.getOwnPropertySymbols is a function');
32

    
33
	var obj = {};
34
	var sym = Symbol('test');
35
	var symObj = Object(sym);
36
	t.notEqual(typeof sym, 'string', 'Symbol is not a string');
37
	t.equal(Object.prototype.toString.call(sym), '[object Symbol]', 'symbol primitive Object#toStrings properly');
38
	t.equal(Object.prototype.toString.call(symObj), '[object Symbol]', 'symbol primitive Object#toStrings properly');
39

    
40
	var symVal = 42;
41
	obj[sym] = symVal;
42
	for (sym in obj) { t.fail('symbol property key was found in for..in of object'); }
43

    
44
	t.deepEqual(Object.keys(obj), [], 'no enumerable own keys on symbol-valued object');
45
	t.deepEqual(Object.getOwnPropertyNames(obj), [], 'no own names on symbol-valued object');
46
	t.deepEqual(Object.getOwnPropertySymbols(obj), [sym], 'one own symbol on symbol-valued object');
47
	t.equal(Object.prototype.propertyIsEnumerable.call(obj, sym), true, 'symbol is enumerable');
48
	t.deepEqual(Object.getOwnPropertyDescriptor(obj, sym), {
49
		configurable: true,
50
		enumerable: true,
51
		value: 42,
52
		writable: true
53
	}, 'property descriptor is correct');
54
};
(2-2/2)