2020-08-26 01:57:08 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var test = require('tape');
|
|
|
|
var isDate = require('../');
|
2022-11-10 11:43:16 +01:00
|
|
|
var hasToStringTag = require('has-tostringtag/shams')();
|
2020-08-26 01:57:08 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2022-11-10 11:43:16 +01:00
|
|
|
test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
|
2020-08-26 01:57:08 +02:00
|
|
|
var realDate = new Date();
|
|
|
|
var fakeDate = {
|
|
|
|
toString: function () { return String(realDate); },
|
|
|
|
valueOf: function () { return realDate.getTime(); }
|
|
|
|
};
|
|
|
|
fakeDate[Symbol.toStringTag] = '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();
|
|
|
|
});
|