Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ function getCommonAncestor(node) {
}

var nodes = slice.call(arguments, 1)
var list = parents(node)
list.unshift(node)

return parents(node).filter(function (parent) {
return list.filter(function (parent) {
return nodes.every(function (node) {
return contains(parent, node)
})
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ test("is correct", function (assert) {
assert.end()
})

test("is correct with inner child", function (assert) {
var one = elem()
var two = elem()
var three = elem()

one.appendChild(two)
two.appendChild(three)

var ancestor = commonAncestors(two, three)

assert.equal(ancestor, two)
assert.end()
})

test("doesn't return false positives", function (assert) {
var one = elem()
var two = elem()
Expand Down