source: node_modules/traverse/test/keys.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: 644 bytes
Line 
1'use strict';
2
3var test = require('tape');
4var traverse = require('../');
5
6test('sort test', function (t) {
7 var acc = [];
8 traverse({
9 a: 30,
10 b: 22,
11 id: 9,
12 }).forEach(function (node) {
13 if (!Array.isArray(node) && typeof node === 'object') {
14 this.before(function (beforeNode) {
15 this.keys = Object.keys(beforeNode);
16 this.keys.sort(function (a, b) {
17 var aA = [a === 'id' ? 0 : 1, a];
18 var bA = [b === 'id' ? 0 : 1, b];
19 return aA < bA ? -1 : aA > bA ? 1 : 0;
20 });
21 });
22 }
23 if (this.isLeaf) { acc.push(node); }
24 });
25
26 t.equal(
27 acc.join(' '),
28 '9 30 22',
29 'Traversal in a custom order'
30 );
31
32 t.end();
33});
Note: See TracBrowser for help on using the repository browser.