index.js 1.4 KB

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