Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/unbox-primitive/test/index.js
r0c6b92a r79a0317 5 5 var is = require('object-is'); 6 6 var forEach = require('for-each'); 7 var hasSymbols = require('has-symbols')(); 8 var hasBigInts = require('has-bigints')(); 7 var v = require('es-value-fixtures'); 9 8 10 9 var unboxPrimitive = require('..'); 11 10 12 var debug = function (v, m) { return inspect(v) + ' ' + m; }; 11 test('primitives', function (t) { 12 forEach([null, undefined], function (nullValue) { 13 t['throws']( 14 // @ts-expect-error 15 function () { unboxPrimitive(nullValue); }, 16 TypeError, 17 inspect(nullValue) + ' is not a primitive' 18 ); 19 }); 13 20 14 test('primitives', function (t) { 15 var primitives = [ 16 true, 17 false, 18 '', 19 'foo', 20 42, 21 NaN, 22 Infinity, 23 0 24 ]; 25 if (hasSymbols) { 26 primitives.push(Symbol(), Symbol.iterator, Symbol('f')); 27 } 28 if (hasBigInts) { 29 primitives.push(BigInt(42), BigInt(0)); 30 } 31 forEach(primitives, function (primitive) { 21 // eslint-disable-next-line no-extra-parens 22 forEach(/** @type {typeof v.nonNullPrimitives} */ ([].concat( 23 // @ts-expect-error TS sucks with concat 24 v.nonNullPrimitives, 25 v.zeroes, 26 v.infinities, 27 NaN 28 )), function (primitive) { 32 29 var obj = Object(primitive); 33 30 t.ok( 34 31 is(unboxPrimitive(obj), primitive), 35 debug(obj, 'unboxes to ' + inspect(primitive))32 inspect(obj) + 'unboxes to ' + inspect(primitive) 36 33 ); 37 34 }); … … 41 38 42 39 test('objects', function (t) { 43 var objects = [ 40 // eslint-disable-next-line no-extra-parens 41 forEach(/** @type {typeof v.objects} */ (/** @type {unknown} */ ([].concat( 42 // @ts-expect-error TS sucks with concat 43 v.objects, 44 44 {}, 45 45 [], … … 47 47 /a/g, 48 48 new Date() 49 ]; 50 forEach(objects, function (object) { 49 ))), function (object) { 51 50 t['throws']( 51 // @ts-expect-error 52 52 function () { unboxPrimitive(object); }, 53 53 TypeError, 54 debug(object, 'is not a primitive')54 inspect(object) + ' is not a primitive' 55 55 ); 56 56 });
Note:
See TracChangeset
for help on using the changeset viewer.