]> source.dussan.org Git - svg.js.git/commitdiff
Add test for closest matching parent
authorMorgan Harris <gormster@me.com>
Tue, 23 Nov 2021 02:11:12 +0000 (13:11 +1100)
committerMorgan Harris <gormster@me.com>
Tue, 23 Nov 2021 02:11:12 +0000 (13:11 +1100)
spec/spec/elements/Element.js

index 0d7fa5541c89fd1fc8c11c380558f52459842be4..507637361646deb80446b9f3d6b0b98677b337c2 100644 (file)
@@ -175,6 +175,19 @@ describe('Element.js', function () {
       expect(rect.parents(group1).length).toBe(3)
       expect(rect.parents()).toEqual([ group3, group2, group1, canvas ])
     })
+
+    it('returns array of parents until the closest matching parent', () => {
+      const canvas = SVG().addTo(container)
+      const groupA = canvas.group().addClass('test')
+      const group1 = canvas.group().addClass('test')
+      const group2 = group1.group().addClass('test').addClass('foo')
+      const group3 = group2.group().addClass('foo')
+      const rect = group3.rect(100, 100)
+
+      expect(rect.parents('.test')).toEqual([ group3, group2 ])
+      expect(rect.parents('.foo')).toEqual([ group3 ])
+      expect(rect.parents('.test:not(.foo)')).toEqual([ group3, group2, group1 ])
+    })
   })
 
   describe('reference()', () => {