[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var test = require('tape');
|
---|
| 4 | var isDate = require('../');
|
---|
| 5 | var hasToStringTag = require('has-tostringtag/shams')();
|
---|
| 6 |
|
---|
| 7 | test('not Dates', function (t) {
|
---|
| 8 | t.notOk(isDate(), 'undefined is not Date');
|
---|
| 9 | t.notOk(isDate(null), 'null is not Date');
|
---|
| 10 | t.notOk(isDate(false), 'false is not Date');
|
---|
| 11 | t.notOk(isDate(true), 'true is not Date');
|
---|
| 12 | t.notOk(isDate(42), 'number is not Date');
|
---|
| 13 | t.notOk(isDate('foo'), 'string is not Date');
|
---|
| 14 | t.notOk(isDate([]), 'array is not Date');
|
---|
| 15 | t.notOk(isDate({}), 'object is not Date');
|
---|
| 16 | t.notOk(isDate(function () {}), 'function is not Date');
|
---|
| 17 | t.notOk(isDate(/a/g), 'regex literal is not Date');
|
---|
| 18 | t.notOk(isDate(new RegExp('a', 'g')), 'regex object is not Date');
|
---|
| 19 | t.end();
|
---|
| 20 | });
|
---|
| 21 |
|
---|
| 22 | test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
|
---|
| 23 | var realDate = new Date();
|
---|
| 24 | var fakeDate = {
|
---|
| 25 | toString: function () { return String(realDate); },
|
---|
| 26 | valueOf: function () { return realDate.getTime(); }
|
---|
| 27 | };
|
---|
| 28 | fakeDate[Symbol.toStringTag] = 'Date';
|
---|
| 29 | t.notOk(isDate(fakeDate), 'fake Date with @@toStringTag "Date" is not Date');
|
---|
| 30 | t.end();
|
---|
| 31 | });
|
---|
| 32 |
|
---|
| 33 | test('Dates', function (t) {
|
---|
| 34 | t.ok(isDate(new Date()), 'new Date() is Date');
|
---|
| 35 | t.end();
|
---|
| 36 | });
|
---|