test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var test = require('tape')
  2. var isFunction = require('./index.js')
  3. test('isFunction', function (t) {
  4. t.ok(!isFunction(), 'undefined is not a function')
  5. t.ok(!isFunction(null), 'null is not a function')
  6. t.ok(!isFunction(''), 'string is not a function')
  7. t.ok(!isFunction(/a/), 'regex is not a function')
  8. t.ok(!isFunction(true), 'true is not a function')
  9. t.ok(!isFunction(false), 'false is not a function')
  10. t.ok(!isFunction(NaN), 'NaN is not a function')
  11. t.ok(!isFunction(42), '42 is not a function')
  12. t.ok(isFunction(function () {}), 'function is a function')
  13. t.ok(isFunction(setTimeout), 'setTimeout is a function')
  14. t.end()
  15. })
  16. if (typeof window !== 'undefined') {
  17. test('browser quirks', function (t) {
  18. t.plan(2)
  19. t.ok(isFunction(window.alert), 'alert is a function')
  20. window.testRegExpFromIframe = function (regexp) {
  21. t.ok(!isFunction(regexp))
  22. }
  23. var iframe = document.createElement('iframe')
  24. document.body.appendChild(iframe)
  25. iframe.contentWindow.document.write([
  26. "<html><body><script type=\"text/javascript\">",
  27. "parent.testRegExpFromIframe(/a/)",
  28. "</script></body></html>"
  29. ].join("\n"));
  30. })
  31. }