|
79 | 79 | doubled = _([1, 2, 3]).map(function(num){ return num * 2; });
|
80 | 80 | deepEqual(doubled, [2, 4, 6], 'OO-style doubled numbers');
|
81 | 81 |
|
82 |
| - if (typeof document != 'undefined') { |
83 |
| - var nodes = _.filter(document.getElementById('map-test').childNodes, _.isElement); |
84 |
| - var ids = _.map(nodes, 'id'); |
85 |
| - equal(nodes.length, 2); |
86 |
| - deepEqual(ids, ['id1', 'id2'], 'Can use collection methods on NodeLists.'); |
87 |
| - } |
88 |
| - |
89 |
| - ids = _.map({length: 2, 0: {id: '1'}, 1: {id: '2'}}, function(n){ |
| 82 | + var ids = _.map({length: 2, 0: {id: '1'}, 1: {id: '2'}}, function(n){ |
90 | 83 | return n.id;
|
91 | 84 | });
|
92 | 85 | deepEqual(ids, ['1', '2'], 'Can use collection methods on Array-likes.');
|
|
711 | 704 | }, predicate);
|
712 | 705 | });
|
713 | 706 |
|
| 707 | + if (typeof document != 'undefined') { |
| 708 | + test('Can use various collection methods on NodeLists', function() { |
| 709 | + var parent = document.createElement('div'); |
| 710 | + parent.innerHTML = '<span id=id1></span>textnode<span id=id2></span>'; |
| 711 | + |
| 712 | + var elementChildren = _.filter(parent.childNodes, _.isElement); |
| 713 | + equal(elementChildren.length, 2); |
| 714 | + |
| 715 | + deepEqual(_.map(elementChildren, 'id'), ['id1', 'id2']); |
| 716 | + deepEqual(_.map(parent.childNodes, 'nodeType'), [1, 3, 1]); |
| 717 | + |
| 718 | + ok(!_.every(parent.childNodes, _.isElement)); |
| 719 | + ok(_.some(parent.childNodes, _.isElement)); |
| 720 | + |
| 721 | + function compareNode(node) { |
| 722 | + return _.isElement(node) ? node.id.charAt(2) : void 0; |
| 723 | + } |
| 724 | + equal(_.max(parent.childNodes, compareNode), _.last(parent.childNodes)); |
| 725 | + equal(_.min(parent.childNodes, compareNode), _.first(parent.childNodes)); |
| 726 | + }); |
| 727 | + } |
| 728 | + |
714 | 729 | }());
|
0 commit comments