Skip to content

Commit

Permalink
Add toStringTag tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 30, 2015
1 parent dc528dd commit f48a83a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var test = require('tape');
var isRegex = require('./');
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';

test('not regexes', function (t) {
t.notOk(isRegex(), 'undefined is not regex');
Expand All @@ -16,9 +17,16 @@ test('not regexes', function (t) {
t.end();
});

test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
var regex = /a/g;
var fakeRegex = { valueOf: function () { return regex; }, toString: function () { return String(regex); } };
fakeRegex[Symbol.toStringTag] = function () { return 'RegExp'; };
t.notOk(isRegex(fakeRegex), 'fake RegExp with @@toStringTag "RegExp" is not regex');
t.end();
});

test('regexes', function (t) {
t.ok(isRegex(/a/g), 'regex literal is regex');
t.ok(isRegex(new RegExp('a', 'g')), 'regex object is regex');
t.end();
});

0 comments on commit f48a83a

Please sign in to comment.