index.js 1.3 KB

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