Add test to make sure `include-fragment-replaced` is called once

This commit is contained in:
Kristján Oddsson 2022-03-31 15:50:34 +01:00
Родитель ee0dc3c110
Коммит 155a8cb84c
1 изменённых файлов: 20 добавлений и 0 удалений

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

@ -587,4 +587,24 @@ suite('include-fragment-element', function () {
assert.equal(document.querySelector('#replaced').textContent, 'hello')
})
})
test('include-fragment-replaced is only called once', function () {
const div = document.createElement('div')
div.hidden = true
document.body.append(div)
div.innerHTML = `<include-fragment src="/hello">loading</include-fragment>`
div.firstChild.addEventListener('include-fragment-replaced', () => (loadCount += 1))
let loadCount = 0
setTimeout(() => {
div.hidden = false
}, 0)
return when(div.firstChild, 'include-fragment-replaced').then(() => {
assert.equal(loadCount, 1, 'Load occured too many times')
assert.equal(document.querySelector('include-fragment'), null)
assert.equal(document.querySelector('#replaced').textContent, 'hello')
})
})
})