diff --git a/package.json b/package.json index e22ad4e..e78d227 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "auto-changelog": "^2.4.0", "available-regexp-flags": "^1.0.2", "eclint": "^2.8.1", + "es-value-fixtures": "^1.4.2", "eslint": "=8.8.0", "for-each": "^0.3.3", "functions-have-names": "^1.2.3", diff --git a/test/tests.js b/test/tests.js index 8b6641d..fbe4194 100644 --- a/test/tests.js +++ b/test/tests.js @@ -3,6 +3,7 @@ var hasOwn = require('hasown'); var inspect = require('object-inspect'); var supportsDescriptors = require('define-properties').supportsDescriptors; +var v = require('es-value-fixtures'); var forEach = require('for-each'); var availableFlags = require('available-regexp-flags'); @@ -19,6 +20,14 @@ var getRegexLiteral = function (stringRegex) { }; module.exports = function runTests(flags, t) { + forEach(v.primitives, function (nonObject) { + t['throws']( + function () { flags(nonObject); }, + TypeError, + 'throws when called with a non-object receiver: ' + inspect(nonObject) + ); + }); + t.equal(flags(/a/g), 'g', 'flags(/a/g) !== "g"'); t.equal(flags(/a/gmi), 'gim', 'flags(/a/gmi) !== "gim"'); t.equal(flags(new RegExp('a', 'gmi')), 'gim', 'flags(new RegExp("a", "gmi")) !== "gim"'); @@ -85,15 +94,6 @@ module.exports = function runTests(flags, t) { st.end(); }); - t.test('throws properly', function (st) { - var nonObjects = ['', false, true, 42, NaN, null, undefined]; - st.plan(nonObjects.length); - var throwsOnNonObject = function (nonObject) { - st['throws'](flags.bind(null, nonObject), TypeError, inspect(nonObject) + ' is not an Object'); - }; - nonObjects.forEach(throwsOnNonObject); - }); - t.test('getters', { skip: !supportsDescriptors }, function (st) { /* eslint getter-return: 0 */ var calls = '';