@@ -225,20 +225,20 @@ describe( 'Node', () => {
225225 expect ( textBA . getAncestors ( ) ) . to . deep . equal ( [ root , two ] ) ;
226226 } ) ;
227227
228- it ( 'should include itself if includeNode option is set to true' , ( ) => {
229- expect ( root . getAncestors ( { includeNode : true } ) ) . to . deep . equal ( [ root ] ) ;
230- expect ( two . getAncestors ( { includeNode : true } ) ) . to . deep . equal ( [ root , two ] ) ;
231- expect ( textBA . getAncestors ( { includeNode : true } ) ) . to . deep . equal ( [ root , two , textBA ] ) ;
232- expect ( img . getAncestors ( { includeNode : true } ) ) . to . deep . equal ( [ root , two , img ] ) ;
233- expect ( textR . getAncestors ( { includeNode : true } ) ) . to . deep . equal ( [ root , two , textR ] ) ;
228+ it ( 'should include itself if includeSelf option is set to true' , ( ) => {
229+ expect ( root . getAncestors ( { includeSelf : true } ) ) . to . deep . equal ( [ root ] ) ;
230+ expect ( two . getAncestors ( { includeSelf : true } ) ) . to . deep . equal ( [ root , two ] ) ;
231+ expect ( textBA . getAncestors ( { includeSelf : true } ) ) . to . deep . equal ( [ root , two , textBA ] ) ;
232+ expect ( img . getAncestors ( { includeSelf : true } ) ) . to . deep . equal ( [ root , two , img ] ) ;
233+ expect ( textR . getAncestors ( { includeSelf : true } ) ) . to . deep . equal ( [ root , two , textR ] ) ;
234234 } ) ;
235235
236236 it ( 'should reverse order if parentFirst option is set to true' , ( ) => {
237- expect ( root . getAncestors ( { includeNode : true , parentFirst : true } ) ) . to . deep . equal ( [ root ] ) ;
238- expect ( two . getAncestors ( { includeNode : true , parentFirst : true } ) ) . to . deep . equal ( [ two , root ] ) ;
239- expect ( textBA . getAncestors ( { includeNode : true , parentFirst : true } ) ) . to . deep . equal ( [ textBA , two , root ] ) ;
240- expect ( img . getAncestors ( { includeNode : true , parentFirst : true } ) ) . to . deep . equal ( [ img , two , root ] ) ;
241- expect ( textR . getAncestors ( { includeNode : true , parentFirst : true } ) ) . to . deep . equal ( [ textR , two , root ] ) ;
237+ expect ( root . getAncestors ( { includeSelf : true , parentFirst : true } ) ) . to . deep . equal ( [ root ] ) ;
238+ expect ( two . getAncestors ( { includeSelf : true , parentFirst : true } ) ) . to . deep . equal ( [ two , root ] ) ;
239+ expect ( textBA . getAncestors ( { includeSelf : true , parentFirst : true } ) ) . to . deep . equal ( [ textBA , two , root ] ) ;
240+ expect ( img . getAncestors ( { includeSelf : true , parentFirst : true } ) ) . to . deep . equal ( [ img , two , root ] ) ;
241+ expect ( textR . getAncestors ( { includeSelf : true , parentFirst : true } ) ) . to . deep . equal ( [ textR , two , root ] ) ;
242242 } ) ;
243243 } ) ;
244244
@@ -247,11 +247,18 @@ describe( 'Node', () => {
247247 expect ( img . getCommonAncestor ( img ) ) . to . equal ( two ) ;
248248 } ) ;
249249
250+ it ( 'should return the given node for the same node if includeSelf is used' , ( ) => {
251+ expect ( img . getCommonAncestor ( img , { includeSelf : true } ) ) . to . equal ( img ) ;
252+ } ) ;
253+
250254 it ( 'should return null for detached subtrees' , ( ) => {
251255 const detached = new Element ( 'foo' ) ;
252256
253257 expect ( img . getCommonAncestor ( detached ) ) . to . be . null ;
254258 expect ( detached . getCommonAncestor ( img ) ) . to . be . null ;
259+
260+ expect ( img . getCommonAncestor ( detached , { includeSelf : true } ) ) . to . be . null ;
261+ expect ( detached . getCommonAncestor ( img , { includeSelf : true } ) ) . to . be . null ;
255262 } ) ;
256263
257264 it ( 'should return null when one of the nodes is a tree root itself' , ( ) => {
@@ -260,9 +267,18 @@ describe( 'Node', () => {
260267 expect ( root . getCommonAncestor ( root ) ) . to . be . null ;
261268 } ) ;
262269
270+ it ( 'should return root when one of the nodes is a tree root itself and includeSelf is used' , ( ) => {
271+ expect ( root . getCommonAncestor ( img , { includeSelf : true } ) ) . to . equal ( root ) ;
272+ expect ( img . getCommonAncestor ( root , { includeSelf : true } ) ) . to . equal ( root ) ;
273+ expect ( root . getCommonAncestor ( root , { includeSelf : true } ) ) . to . equal ( root ) ;
274+ } ) ;
275+
263276 it ( 'should return parent of the nodes at the same level' , ( ) => {
264- expect ( img . getCommonAncestor ( textBA ) ) . to . equal ( two ) ;
265- expect ( textR . getCommonAncestor ( textBA ) ) . to . equal ( two ) ;
277+ expect ( img . getCommonAncestor ( textBA ) , 1 ) . to . equal ( two ) ;
278+ expect ( textR . getCommonAncestor ( textBA ) , 2 ) . to . equal ( two ) ;
279+
280+ expect ( img . getCommonAncestor ( textBA , { includeSelf : true } ) , 3 ) . to . equal ( two ) ;
281+ expect ( textR . getCommonAncestor ( textBA , { includeSelf : true } ) , 4 ) . to . equal ( two ) ;
266282 } ) ;
267283
268284 it ( 'should return proper element for nodes in different branches and on different levels' , ( ) => {
@@ -282,6 +298,14 @@ describe( 'Node', () => {
282298 expect ( c . getCommonAncestor ( b ) , 3 ) . to . equal ( a ) ;
283299 expect ( bom . getCommonAncestor ( d ) , 4 ) . to . equal ( a ) ;
284300 expect ( b . getCommonAncestor ( bom ) , 5 ) . to . equal ( a ) ;
301+ expect ( b . getCommonAncestor ( bar ) , 6 ) . to . equal ( a ) ;
302+
303+ expect ( bar . getCommonAncestor ( foo , { includeSelf : true } ) , 11 ) . to . equal ( c ) ;
304+ expect ( foo . getCommonAncestor ( d , { includeSelf : true } ) , 12 ) . to . equal ( c ) ;
305+ expect ( c . getCommonAncestor ( b , { includeSelf : true } ) , 13 ) . to . equal ( b ) ;
306+ expect ( bom . getCommonAncestor ( d , { includeSelf : true } ) , 14 ) . to . equal ( a ) ;
307+ expect ( b . getCommonAncestor ( bom , { includeSelf : true } ) , 15 ) . to . equal ( a ) ;
308+ expect ( b . getCommonAncestor ( bar , { includeSelf : true } ) , 16 ) . to . equal ( b ) ;
285309 } ) ;
286310
287311 it ( 'should return document fragment' , ( ) => {
0 commit comments