UNPKG

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