Ignore:
Timestamp:
01/21/25 03:08:24 (2 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
0c6b92a
Message:

F4 Finalna Verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/node_modules/is-symbol/test/index.js

    r0c6b92a r79a0317  
    22
    33var test = require('tape');
     4var forEach = require('for-each');
     5var v = require('es-value-fixtures');
     6
    47var isSymbol = require('../index');
    58
    6 var forEach = function (arr, func) {
    7         var i;
    8         for (i = 0; i < arr.length; ++i) {
    9                 func(arr[i], i, arr);
    10         }
    11 };
    12 
    139var hasSymbols = require('has-symbols')();
     10var hasToStringTag = require('has-tostringtag/shams')();
    1411var inspect = require('object-inspect');
    15 var debug = function (v, m) { return inspect(v) + ' ' + m; };
    1612
    1713test('non-symbol values', function (t) {
    18         var nonSymbols = [
    19                 true,
    20                 false,
     14        var nonSymbols = v.nonSymbolPrimitives.concat(
    2115                Object(true),
    2216                Object(false),
    23                 null,
    24                 undefined,
     17                // @ts-expect-error TS sucks with concat
    2518                {},
    2619                [],
    2720                /a/g,
    28                 'string',
    29                 42,
    3021                new Date(),
    3122                function () {},
    3223                NaN
    33         ];
     24        );
    3425        t.plan(nonSymbols.length);
    3526        forEach(nonSymbols, function (nonSymbol) {
    36                 t.equal(false, isSymbol(nonSymbol), debug(nonSymbol, 'is not a symbol'));
     27                t.equal(isSymbol(nonSymbol), false, inspect(nonSymbol) + ' is not a symbol');
    3728        });
    3829        t.end();
     
    4233        t.test('real symbol valueOf', { skip: !hasSymbols }, function (st) {
    4334                var fakeSymbol = { valueOf: function () { return Symbol('foo'); } };
    44                 st.equal(false, isSymbol(fakeSymbol), 'object with valueOf returning a symbol is not a symbol');
     35                st.equal(isSymbol(fakeSymbol), false, 'object with valueOf returning a symbol is not a symbol');
    4536                st.end();
    4637        });
    4738
    48         t.test('faked @@toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (st) {
     39        t.test('faked @@toStringTag', { skip: !hasToStringTag }, function (st) {
     40                /** @type {{ valueOf(): unknown; [Symbol.toStringTag]?: unknown }} */
    4941                var fakeSymbol = { valueOf: function () { return Symbol('foo'); } };
    5042                fakeSymbol[Symbol.toStringTag] = 'Symbol';
    51                 st.equal(false, isSymbol(fakeSymbol), 'object with fake Symbol @@toStringTag and valueOf returning a symbol is not a symbol');
     43                st.equal(isSymbol(fakeSymbol), false, 'object with fake Symbol @@toStringTag and valueOf returning a symbol is not a symbol');
     44
     45                /** @type {{ valueOf(): unknown; [Symbol.toStringTag]?: unknown }} */
    5246                var notSoFakeSymbol = { valueOf: function () { return 42; } };
    5347                notSoFakeSymbol[Symbol.toStringTag] = 'Symbol';
    54                 st.equal(false, isSymbol(notSoFakeSymbol), 'object with fake Symbol @@toStringTag and valueOf not returning a symbol is not a symbol');
     48                st.equal(isSymbol(notSoFakeSymbol), false, 'object with fake Symbol @@toStringTag and valueOf not returning a symbol is not a symbol');
    5549                st.end();
    5650        });
    5751
    5852        var fakeSymbolString = { toString: function () { return 'Symbol(foo)'; } };
    59         t.equal(false, isSymbol(fakeSymbolString), 'object with toString returning Symbol(foo) is not a symbol');
     53        t.equal(isSymbol(fakeSymbolString), false, 'object with toString returning Symbol(foo) is not a symbol');
    6054
    6155        t.end();
     
    6458test('Symbol support', { skip: !hasSymbols }, function (t) {
    6559        t.test('well-known Symbols', function (st) {
     60                /** @type {(name: string) => name is Exclude<keyof SymbolConstructor, 'for' | 'keyFor'>} */
    6661                var isWellKnown = function filterer(name) {
    6762                        return name !== 'for' && name !== 'keyFor' && !(name in filterer);
     
    6964                var wellKnownSymbols = Object.getOwnPropertyNames(Symbol).filter(isWellKnown);
    7065                wellKnownSymbols.forEach(function (name) {
    71                         var sym = Symbol[name];
    72                         st.equal(true, isSymbol(sym), debug(sym, ' is a symbol'));
     66                        // eslint-disable-next-line no-extra-parens
     67                        var sym = Symbol[/** @type {keyof SymbolConstructor} */ (name)];
     68                        st.equal(isSymbol(sym), true, inspect(sym) + ' is a symbol');
    7369                });
    7470                st.end();
     
    7672
    7773        t.test('user-created symbols', function (st) {
    78                 var symbols = [
     74                var symbols = v.symbols.concat(
    7975                        Symbol(),
    8076                        Symbol('foo'),
    8177                        Symbol['for']('foo'),
    8278                        Object(Symbol('object'))
    83                 ];
     79                );
    8480                symbols.forEach(function (sym) {
    85                         st.equal(true, isSymbol(sym), debug(sym, ' is a symbol'));
     81                        st.equal(isSymbol(sym), true, inspect(sym) + ' is a symbol');
    8682                });
    8783                st.end();
Note: See TracChangeset for help on using the changeset viewer.