index.js 1.6 KB

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