1 | 'use strict';
|
---|
2 |
|
---|
3 | var test = require('tape');
|
---|
4 | var inspect = require('object-inspect');
|
---|
5 | var is = require('object-is');
|
---|
6 | var forEach = require('for-each');
|
---|
7 | var v = require('es-value-fixtures');
|
---|
8 |
|
---|
9 | var unboxPrimitive = require('..');
|
---|
10 |
|
---|
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 | });
|
---|
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 |
|
---|
39 | test('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 | });
|
---|