tests.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. module.exports = function (numberIsNaN, t) {
  3. t.test('not NaN', function (st) {
  4. st.test('primitives', function (sst) {
  5. sst.notOk(numberIsNaN(), 'undefined is not NaN');
  6. sst.notOk(numberIsNaN(null), 'null is not NaN');
  7. sst.notOk(numberIsNaN(false), 'false is not NaN');
  8. sst.notOk(numberIsNaN(true), 'true is not NaN');
  9. sst.notOk(numberIsNaN(0), 'positive zero is not NaN');
  10. sst.notOk(numberIsNaN(Infinity), 'Infinity is not NaN');
  11. sst.notOk(numberIsNaN(-Infinity), '-Infinity is not NaN');
  12. sst.notOk(numberIsNaN('foo'), 'string is not NaN');
  13. sst.notOk(numberIsNaN('NaN'), 'string NaN is not NaN');
  14. sst.end();
  15. });
  16. st.notOk(numberIsNaN([]), 'array is not NaN');
  17. st.notOk(numberIsNaN({}), 'object is not NaN');
  18. st.notOk(numberIsNaN(function () {}), 'function is not NaN');
  19. st.test('valueOf', function (vt) {
  20. var obj = {
  21. valueOf: function () {
  22. return NaN;
  23. }
  24. };
  25. vt.ok(numberIsNaN(Number(obj)), 'object with valueOf of NaN, converted to Number, is NaN');
  26. vt.notOk(numberIsNaN(obj), 'object with valueOf of NaN is not NaN');
  27. vt.end();
  28. });
  29. st.end();
  30. });
  31. t.test('NaN literal', function (st) {
  32. st.ok(numberIsNaN(NaN), 'NaN is NaN');
  33. st.end();
  34. });
  35. };