simple-is-tests.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. var _test = require("tap").test;
  3. var is = require("../");
  4. function test(name, fn) {
  5. return _test(name, function(t) {
  6. fn(t, t.ok.bind(t), t.notOk.bind(t));
  7. });
  8. }
  9. test("various", function(t, yes, no) {
  10. function fn() {
  11. }
  12. yes(is.nan(NaN));
  13. no(is.nan(1));
  14. no(is.nan("asdf"));
  15. yes(is.boolean(true));
  16. no(is.boolean(new Boolean(true)));
  17. yes(is.number(1));
  18. no(is.number(new Number(1)));
  19. yes(is.string("asdf"));
  20. no(is.string(new String("asdf")));
  21. yes(is.fn(fn));
  22. no(is.fn({}));
  23. yes(is.object({}));
  24. no(is.object(null));
  25. no(is.object(fn));
  26. yes([null, undefined, true, 1, "asdf"].every(is.primitive));
  27. no([{}, fn, new Number(1), /regexp/].some(is.primitive));
  28. yes(is.array([]));
  29. yes(is.finitenumber(1));
  30. yes(is.finitenumber(1.1));
  31. no(is.finitenumber(NaN));
  32. no(is.finitenumber(Infinity));
  33. no(is.finitenumber(-Infinity));
  34. no(is.finitenumber("1"));
  35. yes(is.someof(1, [-1, 1, 3]));
  36. yes(is.someof("x", [0, 1, "x"]));
  37. no(is.someof(1, ["1"]));
  38. no(is.noneof(1, [-1, 1, 3]));
  39. no(is.noneof("x", [0, 1, "x"]));
  40. yes(is.noneof(1, ["1"]));
  41. yes(is.own({a: 1}, "a"));
  42. no(is.own({a: 1}, "b"));
  43. no(is.own({a: 1}, "toString"));
  44. t.end();
  45. });