Skip to content

Commit f48a83a

Browse files
committed
Add toStringTag tests.
1 parent dc528dd commit f48a83a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var test = require('tape');
44
var isRegex = require('./');
5+
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
56

67
test('not regexes', function (t) {
78
t.notOk(isRegex(), 'undefined is not regex');
@@ -16,9 +17,16 @@ test('not regexes', function (t) {
1617
t.end();
1718
});
1819

20+
test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
21+
var regex = /a/g;
22+
var fakeRegex = { valueOf: function () { return regex; }, toString: function () { return String(regex); } };
23+
fakeRegex[Symbol.toStringTag] = function () { return 'RegExp'; };
24+
t.notOk(isRegex(fakeRegex), 'fake RegExp with @@toStringTag "RegExp" is not regex');
25+
t.end();
26+
});
27+
1928
test('regexes', function (t) {
2029
t.ok(isRegex(/a/g), 'regex literal is regex');
2130
t.ok(isRegex(new RegExp('a', 'g')), 'regex object is regex');
2231
t.end();
2332
});
24-

0 commit comments

Comments
 (0)