Skip to content

Commit

Permalink
[Tests] use es-value-fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 16, 2024
1 parent e29ff5f commit a321ae5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@ljharb/eslint-config": "^21.1.1",
"auto-changelog": "^2.5.0",
"encoding": "^0.1.13",
"es-value-fixtures": "^1.5.0",
"eslint": "=8.8.0",
"for-each": "^0.3.3",
"in-publish": "^2.0.1",
Expand Down
45 changes: 21 additions & 24 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,29 @@ var test = require('tape');
var inspect = require('object-inspect');
var is = require('object-is');
var forEach = require('for-each');
var hasSymbols = require('has-symbols')();
var hasBigInts = require('has-bigints')();
var v = require('es-value-fixtures');

var unboxPrimitive = require('..');

var debug = function (v, m) { return inspect(v) + ' ' + m; };

test('primitives', function (t) {
var primitives = [
true,
false,
'',
'foo',
42,
NaN,
Infinity,
0
];
if (hasSymbols) {
primitives.push(Symbol(), Symbol.iterator, Symbol('f'));
}
if (hasBigInts) {
primitives.push(BigInt(42), BigInt(0));
}
forEach(primitives, function (primitive) {
forEach([null, undefined], function (nullValue) {
t['throws'](
function () { unboxPrimitive(nullValue); },
TypeError,
inspect(nullValue) + ' is not a primitive'
);
});

forEach([].concat(
v.nonNullPrimitives,
v.zeroes,
v.infinities,
NaN
), function (primitive) {
var obj = Object(primitive);
t.ok(
is(unboxPrimitive(obj), primitive),
debug(obj, 'unboxes to ' + inspect(primitive))
inspect(obj) + 'unboxes to ' + inspect(primitive)
);
});

Expand All @@ -47,11 +41,14 @@ test('objects', function (t) {
/a/g,
new Date()
];
forEach(objects, function (object) {
forEach([].concat(
v.objects,
objects
), function (object) {
t['throws'](
function () { unboxPrimitive(object); },
TypeError,
debug(object, 'is not a primitive')
inspect(object) + ' is not a primitive'
);
});

Expand Down

0 comments on commit a321ae5

Please sign in to comment.