source: node_modules/traverse/test/date.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 676 bytes
Line 
1'use strict';
2
3var test = require('tape');
4var traverse = require('../');
5
6test('dateEach', function (t) {
7 var obj = { x: new Date(), y: 10, z: 5 };
8
9 var counts = {};
10
11 traverse(obj).forEach(function (node) {
12 var type = (node instanceof Date && 'Date') || typeof node;
13 counts[type] = (counts[type] || 0) + 1;
14 });
15
16 t.same(counts, {
17 object: 1,
18 Date: 1,
19 number: 2,
20 });
21 t.end();
22});
23
24test('dateMap', function (t) {
25 var obj = { x: new Date(), y: 10, z: 5 };
26
27 var res = traverse(obj).map(function (node) {
28 if (typeof node === 'number') { this.update(node + 100); }
29 });
30
31 t.ok(obj.x !== res.x);
32 t.same(res, {
33 x: obj.x,
34 y: 110,
35 z: 105,
36 });
37 t.end();
38});
39
Note: See TracBrowser for help on using the repository browser.