Skip to content

Commit

Permalink
add getClosestElement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
estevanmaito committed May 17, 2019
1 parent 436f9f5 commit 7cf041e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/__tests__/helpers/getClosestElement.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import getClosestElement from '../../helpers/getClosestElement'

const template = `
<div class="outer">
<div class="inner">
<span class="element"></span>
</div>
</div>
`

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()
})

})

0 comments on commit 7cf041e

Please sign in to comment.