source: imaps-frontend/node_modules/get-symbol-description/test/index.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3var test = require('tape');
4var debug = require('object-inspect');
5var forEach = require('for-each');
6var hasOwn = require('hasown');
7var v = require('es-value-fixtures');
8
9var getSymbolDescription = require('../');
10var getInferredName = require('../getInferredName');
11
12test('getSymbolDescription', function (t) {
13 t.test('no symbols', { skip: v.hasSymbols }, function (st) {
14 st['throws'](
15 getSymbolDescription,
16 SyntaxError,
17 'requires Symbol support'
18 );
19
20 st.end();
21 });
22
23 forEach(v.nonSymbolPrimitives.concat(v.objects), function (nonSymbol) {
24 t['throws'](
25 function () { getSymbolDescription(nonSymbol); },
26 v.hasSymbols ? TypeError : SyntaxError,
27 debug(nonSymbol) + ' is not a Symbol'
28 );
29 });
30
31 t.test('with symbols', { skip: !v.hasSymbols }, function (st) {
32 forEach(
33 [
34 [Symbol(), undefined],
35 [Symbol(undefined), undefined],
36 [Symbol(null), 'null'],
37 [Symbol.iterator, 'Symbol.iterator'],
38 [Symbol('foo'), 'foo']
39 ],
40 function (pair) {
41 var sym = pair[0];
42 var desc = pair[1];
43 st.equal(getSymbolDescription(sym), desc, debug(sym) + ' description is ' + debug(desc));
44 }
45 );
46
47 st.test('only possible when inference or native `Symbol.prototype.description` is supported', {
48 skip: !getInferredName && !hasOwn(Symbol.prototype, 'description')
49 }, function (s2t) {
50 s2t.equal(getSymbolDescription(Symbol('')), '', 'Symbol("") description is ""');
51
52 s2t.end();
53 });
54
55 st.test('only possible when global symbols are supported', {
56 skip: !hasOwn(Symbol, 'for') || !hasOwn(Symbol, 'keyFor')
57 }, function (s2t) {
58 // eslint-disable-next-line no-restricted-properties
59 s2t.equal(getSymbolDescription(Symbol['for']('')), '', 'Symbol.for("") description is ""');
60 s2t.end();
61 });
62
63 st.end();
64 });
65
66 t.end();
67});
Note: See TracBrowser for help on using the repository browser.