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