From 7cf041e977a0c1343f503685c721913c7078aca8 Mon Sep 17 00:00:00 2001 From: Estevan Maito Date: Fri, 17 May 2019 15:29:42 -0300 Subject: [PATCH] add getClosestElement tests --- .../helpers/getClosestElement.test.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/__tests__/helpers/getClosestElement.test.js diff --git a/src/__tests__/helpers/getClosestElement.test.js b/src/__tests__/helpers/getClosestElement.test.js new file mode 100644 index 0000000..cc3cf69 --- /dev/null +++ b/src/__tests__/helpers/getClosestElement.test.js @@ -0,0 +1,27 @@ +import getClosestElement from '../../helpers/getClosestElement' + +const template = ` +
+
+ +
+
+` + +document.body.innerHTML = template +const element = document.querySelector('.element') + +describe('getClosestElement', () => { + it('should return the closest matching ancestor', () => { + const ancestor = getClosestElement(element, 'div') + + expect(ancestor.classList).toContain('inner') + }) + + it('should return null if there isn\'t a matching ancestor', () => { + const ancestor = getClosestElement(element, 'section') + + expect(ancestor).toBeNull() + }) + +})