source: imaps-frontend/node_modules/unbox-primitive/test/index.js@ 79a0317

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d565449]1'use strict';
2
3var test = require('tape');
4var inspect = require('object-inspect');
5var is = require('object-is');
6var forEach = require('for-each');
[79a0317]7var v = require('es-value-fixtures');
[d565449]8
9var unboxPrimitive = require('..');
10
11test('primitives', function (t) {
[79a0317]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 });
20
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) {
[d565449]29 var obj = Object(primitive);
30 t.ok(
31 is(unboxPrimitive(obj), primitive),
[79a0317]32 inspect(obj) + 'unboxes to ' + inspect(primitive)
[d565449]33 );
34 });
35
36 t.end();
37});
38
39test('objects', function (t) {
[79a0317]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,
[d565449]44 {},
45 [],
46 function () {},
47 /a/g,
48 new Date()
[79a0317]49 ))), function (object) {
[d565449]50 t['throws'](
[79a0317]51 // @ts-expect-error
[d565449]52 function () { unboxPrimitive(object); },
53 TypeError,
[79a0317]54 inspect(object) + ' is not a primitive'
[d565449]55 );
56 });
57
58 t.end();
59});
Note: See TracBrowser for help on using the repository browser.