source: frontend/node_modules/unbox-primitive/test/index.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

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