return noSiblingParents;
}
- var i;
- for(i = 0; i < Math.min(parents1.length, parents2.length); i++) {
+ var stop = Math.min(parents1.length, parents2.length),
+ i;
+ for(i = 0; i < stop; i++) {
if(parents1[i].sameNode(parents2[i])) {
continue;
}
break;
}
+ if(i === stop) {
+ i--;
+ }
return {node1: parents1[i], node2: parents2[i]};
},
expect(siblingParents.node1.sameNode(aliceText)).to.equal(true, 'aliceText');
expect(siblingParents.node2.sameNode(span)).to.equal(true, 'span');
});
+
+ it('returns node itself for two same nodes', function() {
+ var doc = getDocumentFromXML('<section><div></div></section>'),
+ div = doc.root.contents()[0];
+
+ var siblingParents = doc.getSiblingParents({node1: div, node2: div});
+ expect(!!siblingParents.node1 && !!siblingParents.node2).to.equal(true, 'nodes defined');
+ expect(siblingParents.node1.sameNode(div)).to.be.equal(true, 'node1');
+ expect(siblingParents.node2.sameNode(div)).to.be.equal(true, 'node2');
+ });
});
});