date.js 772 B

12345678910111213141516171819202122232425262728293031323334353637
  1. var test = require('tape');
  2. var traverse = require('../');
  3. test('dateEach', function (t) {
  4. var obj = { x : new Date, y : 10, z : 5 };
  5. var counts = {};
  6. traverse(obj).forEach(function (node) {
  7. var t = (node instanceof Date && 'Date') || typeof node;
  8. counts[t] = (counts[t] || 0) + 1;
  9. });
  10. t.same(counts, {
  11. object : 1,
  12. Date : 1,
  13. number : 2,
  14. });
  15. t.end();
  16. });
  17. test('dateMap', function (t) {
  18. var obj = { x : new Date, y : 10, z : 5 };
  19. var res = traverse(obj).map(function (node) {
  20. if (typeof node === 'number') this.update(node + 100);
  21. });
  22. t.ok(obj.x !== res.x);
  23. t.same(res, {
  24. x : obj.x,
  25. y : 110,
  26. z : 105,
  27. });
  28. t.end();
  29. });