const NODE_TEXT = 3
const SelectorEngine = {
- matches(element, selector) {
- return element.matches(selector)
- },
-
find(selector, element = document.documentElement) {
return [].concat(...Element.prototype.querySelectorAll.call(element, selector))
},
let ancestor = element.parentNode
while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) {
- if (this.matches(ancestor, selector)) {
+ if (ancestor.matches(selector)) {
parents.push(ancestor)
}
let next = element.nextElementSibling
while (next) {
- if (this.matches(next, selector)) {
+ if (next.matches(selector)) {
return [next]
}
clearFixture()
})
- describe('matches', () => {
- it('should return matched elements', () => {
- fixtureEl.innerHTML = '<div></div>'
-
- expect(SelectorEngine.matches(fixtureEl, 'div')).toEqual(true)
- })
- })
-
describe('find', () => {
it('should find elements', () => {
fixtureEl.innerHTML = '<div></div>'