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

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[d565449]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'](
[79a0317]15 // @ts-expect-error
[d565449]16 getSymbolDescription,
17 SyntaxError,
18 'requires Symbol support'
19 );
20
21 st.end();
22 });
23
[79a0317]24 forEach([].concat(
25 // @ts-expect-error TS sucks with concat
26 v.nonSymbolPrimitives,
27 v.objects
28 ), function (nonSymbol) {
[d565449]29 t['throws'](
30 function () { getSymbolDescription(nonSymbol); },
31 v.hasSymbols ? TypeError : SyntaxError,
32 debug(nonSymbol) + ' is not a Symbol'
33 );
34 });
35
36 t.test('with symbols', { skip: !v.hasSymbols }, function (st) {
37 forEach(
[79a0317]38 // eslint-disable-next-line no-extra-parens
39 /** @type {[symbol, undefined | string][]} */ ([
[d565449]40 [Symbol(), undefined],
41 [Symbol(undefined), undefined],
[79a0317]42 // @ts-expect-error
[d565449]43 [Symbol(null), 'null'],
44 [Symbol.iterator, 'Symbol.iterator'],
45 [Symbol('foo'), 'foo']
[79a0317]46 ]),
[d565449]47 function (pair) {
48 var sym = pair[0];
49 var desc = pair[1];
50 st.equal(getSymbolDescription(sym), desc, debug(sym) + ' description is ' + debug(desc));
51 }
52 );
53
54 st.test('only possible when inference or native `Symbol.prototype.description` is supported', {
55 skip: !getInferredName && !hasOwn(Symbol.prototype, 'description')
56 }, function (s2t) {
57 s2t.equal(getSymbolDescription(Symbol('')), '', 'Symbol("") description is ""');
58
59 s2t.end();
60 });
61
62 st.test('only possible when global symbols are supported', {
63 skip: !hasOwn(Symbol, 'for') || !hasOwn(Symbol, 'keyFor')
64 }, function (s2t) {
65 // eslint-disable-next-line no-restricted-properties
66 s2t.equal(getSymbolDescription(Symbol['for']('')), '', 'Symbol.for("") description is ""');
67 s2t.end();
68 });
69
70 st.end();
71 });
72
73 t.end();
74});
Note: See TracBrowser for help on using the repository browser.