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

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 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');
7var hasSymbols = require('has-symbols')();
8var hasBigInts = require('has-bigints')();
9
10var unboxPrimitive = require('..');
11
12var debug = function (v, m) { return inspect(v) + ' ' + m; };
13
14test('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) {
32 var obj = Object(primitive);
33 t.ok(
34 is(unboxPrimitive(obj), primitive),
35 debug(obj, 'unboxes to ' + inspect(primitive))
36 );
37 });
38
39 t.end();
40});
41
42test('objects', function (t) {
43 var objects = [
44 {},
45 [],
46 function () {},
47 /a/g,
48 new Date()
49 ];
50 forEach(objects, function (object) {
51 t['throws'](
52 function () { unboxPrimitive(object); },
53 TypeError,
54 debug(object, 'is not a primitive')
55 );
56 });
57
58 t.end();
59});
Note: See TracBrowser for help on using the repository browser.