1 | 'use strict';
|
2 |
|
3 | const expect = require('chai').expect;
|
4 | const deepTraverse = require('../lib/util').deepTraverse;
|
5 |
|
6 | describe('Util', function() {
|
7 |
|
8 | describe('deepTraverse()', function() {
|
9 | it('should iterate over all keys nested in an object', function(done) {
|
10 | let object = { 'a': [{ 'b': { 'c': 3 } }] };
|
11 |
|
12 | let keysSeen = [];
|
13 | let valsSeen = [];
|
14 | let parentsSeen = [];
|
15 |
|
16 | deepTraverse(object, function(key, value, parent) {
|
17 | keysSeen.push(key);
|
18 | valsSeen.push(value);
|
19 | parentsSeen.push(parent);
|
20 | });
|
21 |
|
22 | expect(keysSeen).to.have.length(4);
|
23 | expect(keysSeen).to.include('a');
|
24 | expect(keysSeen).to.include('0');
|
25 | expect(keysSeen).to.include('b');
|
26 | expect(keysSeen).to.include('c');
|
27 | expect(valsSeen).to.have.length(4);
|
28 | expect(parentsSeen).to.have.length(4);
|
29 | expect(keysSeen[0]).to.be.equal('a');
|
30 | expect(parentsSeen[1]).to.be.equal(object.a);
|
31 |
|
32 | done();
|
33 | });
|
34 | });
|
35 | }); |
\ | No newline at end of file |