From a321ae56aaf30ea843c708bf6c6c13ee52eee205 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 15 Dec 2024 22:26:15 -0800 Subject: [PATCH] [Tests] use `es-value-fixtures` --- package.json | 1 + test/index.js | 45 +++++++++++++++++++++------------------------ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index f700fc2..f64758e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/index.js b/test/index.js index 73688ac..dfa48f4 100644 --- a/test/index.js +++ b/test/index.js @@ -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) ); }); @@ -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' ); });