source: trip-planner-front/node_modules/has-symbols/test/tests.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1'use strict';
2
3// eslint-disable-next-line consistent-return
4module.exports = function runSymbolTests(t) {
5 t.equal(typeof Symbol, 'function', 'global Symbol is a function');
6
7 if (typeof Symbol !== 'function') { return false; }
8
9 t.notEqual(Symbol(), Symbol(), 'two symbols are not equal');
10
11 /*
12 t.equal(
13 Symbol.prototype.toString.call(Symbol('foo')),
14 Symbol.prototype.toString.call(Symbol('foo')),
15 'two symbols with the same description stringify the same'
16 );
17 */
18
19 /*
20 var foo = Symbol('foo');
21
22 t.notEqual(
23 String(foo),
24 String(Symbol('bar')),
25 'two symbols with different descriptions do not stringify the same'
26 );
27 */
28
29 t.equal(typeof Symbol.prototype.toString, 'function', 'Symbol#toString is a function');
30 // t.equal(String(foo), Symbol.prototype.toString.call(foo), 'Symbol#toString equals String of the same symbol');
31
32 t.equal(typeof Object.getOwnPropertySymbols, 'function', 'Object.getOwnPropertySymbols is a function');
33
34 var obj = {};
35 var sym = Symbol('test');
36 var symObj = Object(sym);
37 t.notEqual(typeof sym, 'string', 'Symbol is not a string');
38 t.equal(Object.prototype.toString.call(sym), '[object Symbol]', 'symbol primitive Object#toStrings properly');
39 t.equal(Object.prototype.toString.call(symObj), '[object Symbol]', 'symbol primitive Object#toStrings properly');
40
41 var symVal = 42;
42 obj[sym] = symVal;
43 // eslint-disable-next-line no-restricted-syntax
44 for (sym in obj) { t.fail('symbol property key was found in for..in of object'); }
45
46 t.deepEqual(Object.keys(obj), [], 'no enumerable own keys on symbol-valued object');
47 t.deepEqual(Object.getOwnPropertyNames(obj), [], 'no own names on symbol-valued object');
48 t.deepEqual(Object.getOwnPropertySymbols(obj), [sym], 'one own symbol on symbol-valued object');
49 t.equal(Object.prototype.propertyIsEnumerable.call(obj, sym), true, 'symbol is enumerable');
50 t.deepEqual(Object.getOwnPropertyDescriptor(obj, sym), {
51 configurable: true,
52 enumerable: true,
53 value: 42,
54 writable: true
55 }, 'property descriptor is correct');
56};
Note: See TracBrowser for help on using the repository browser.