Use real elements now that we have a real DOM

This commit is contained in:
Kristján Oddsson 2020-06-10 11:52:50 +01:00
Родитель 2f4ea9bd6f
Коммит 8581ddff44
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F5C58CF9F8FE5D63
1 изменённых файлов: 8 добавлений и 22 удалений

Просмотреть файл

@ -1,16 +1,12 @@
import {findTarget, findTargets} from '../lib/findtarget.js' import {findTarget, findTargets} from '../lib/findtarget.js'
describe('findTarget', () => { class MyController extends HTMLElement {}
class FakeElement { if (!window.customElements.get('my-controller')) {
closest() {} window.MyController = MyController
} window.customElements.define('my-controller', MyController)
class MyController { }
get tagName() {
return 'my-controller'
}
querySelectorAll() {}
}
describe('findTarget', () => {
it('calls querySelectorAll with the controller name and target name', () => { it('calls querySelectorAll with the controller name and target name', () => {
const instance = new MyController() const instance = new MyController()
chai.spy.on(instance, 'querySelectorAll', () => []) chai.spy.on(instance, 'querySelectorAll', () => [])
@ -19,7 +15,7 @@ describe('findTarget', () => {
}) })
it('returns first element where closest tag is the controller', () => { it('returns first element where closest tag is the controller', () => {
const els = [new FakeElement(), new FakeElement()] const els = [document.createElement('div'), document.createElement('div')]
const instance = new MyController() const instance = new MyController()
chai.spy.on(instance, 'querySelectorAll', () => els) chai.spy.on(instance, 'querySelectorAll', () => els)
chai.spy.on(els[0], 'closest', () => null) chai.spy.on(els[0], 'closest', () => null)
@ -32,16 +28,6 @@ describe('findTarget', () => {
}) })
describe('findTargets', () => { describe('findTargets', () => {
class FakeElement {
closest() {}
}
class MyController {
get tagName() {
return 'my-controller'
}
querySelectorAll() {}
}
it('calls querySelectorAll with the controller name and target name', () => { it('calls querySelectorAll with the controller name and target name', () => {
const instance = new MyController() const instance = new MyController()
chai.spy.on(instance, 'querySelectorAll', () => []) chai.spy.on(instance, 'querySelectorAll', () => [])
@ -50,7 +36,7 @@ describe('findTargets', () => {
}) })
it('returns all elements where closest tag is the controller', () => { it('returns all elements where closest tag is the controller', () => {
const els = [new FakeElement(), new FakeElement(), new FakeElement()] const els = [document.createElement('div'), document.createElement('div'), document.createElement('div')]
const instance = new MyController() const instance = new MyController()
chai.spy.on(instance, 'querySelectorAll', () => els) chai.spy.on(instance, 'querySelectorAll', () => els)
chai.spy.on(els[0], 'closest', () => instance) chai.spy.on(els[0], 'closest', () => instance)