Skip to content

Commit

Permalink
Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 15, 2014
1 parent dd0fd96 commit b6f432f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test.js
@@ -0,0 +1,33 @@
'use strict';

var test = require('tape');
var isDate = require('./');
var hasSymbols = typeof Symbol === 'function' && typeof Symbol() === 'symbol';

test('not Dates', function (t) {
t.notOk(isDate(), 'undefined is not Date');
t.notOk(isDate(null), 'null is not Date');
t.notOk(isDate(false), 'false is not Date');
t.notOk(isDate(true), 'true is not Date');
t.notOk(isDate(42), 'number is not Date');
t.notOk(isDate('foo'), 'string is not Date');
t.notOk(isDate([]), 'array is not Date');
t.notOk(isDate({}), 'object is not Date');
t.notOk(isDate(function () {}), 'function is not Date');
t.notOk(isDate(/a/g), 'regex literal is not Date');
t.notOk(isDate(new RegExp('a', 'g')), 'regex object is not Date');
t.end();
});

test('@@toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (t) {
var realDate = new Date();
var fakeDate = { valueOf: function () { return realDate.getTime(); }, toString: function () { return String(realDate); } };
fakeDate[Symbol.toStringTag] = function () { return 'Date'; };
t.notOk(isDate(fakeDate), 'fake Date with @@toStringTag "Date" is not Date');
t.end();
});

test('Dates', function (t) {
t.ok(isDate(new Date()), 'new Date() is Date');
t.end();
});

0 comments on commit b6f432f

Please sign in to comment.