Skip to content

Commit

Permalink
[Tests] increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 11, 2024
1 parent 1d03d22 commit c692c88
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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"');
Expand Down Expand Up @@ -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 = '';
Expand Down

0 comments on commit c692c88

Please sign in to comment.