This commit is contained in:
Nick Holden 2021-04-09 14:53:28 -07:00
Родитель 7072a51d8b
Коммит c74359cd10
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: EE6A91D1DD9E4BC7
1 изменённых файлов: 26 добавлений и 10 удалений

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

@ -29,7 +29,7 @@ describe('typing-effect', function () {
})
describe('content typing', function () {
it('types a single line', function (done) {
it('types a single line', async function () {
const line = 'Welcome to GitHub!'
const container = document.createElement('div')
container.innerHTML = `
@ -38,16 +38,16 @@ describe('typing-effect', function () {
<span data-target="typing-effect.cursor">|</span>
</typing-effect>
`
const typingEffectElement = container.querySelector('typing-effect')
const contentSpan = container.querySelector('span[data-target="typing-effect.content"]')
document.body.append(container)
setTimeout(() => {
assert.equal(contentSpan.textContent, line)
done()
}, 1500)
await once(typingEffectElement, 'typing:complete')
assert.equal(contentSpan.innerHTML, line)
})
it('types multiple lines', function (done) {
it('types multiple lines', async function () {
const lineOne = 'Welcome!'
const lineTwo = 'Lets begin'
const container = document.createElement('div')
@ -57,13 +57,29 @@ describe('typing-effect', function () {
<span data-target="typing-effect.cursor">|</span>
</typing-effect>
`
const typingEffectElement = container.querySelector('typing-effect')
const contentSpan = container.querySelector('span[data-target="typing-effect.content"]')
document.body.append(container)
setTimeout(() => {
assert.equal(contentSpan.innerHTML, `${lineOne}<br>${lineTwo}`)
done()
}, 1500)
await once(typingEffectElement, 'typing:complete')
assert.equal(contentSpan.innerHTML, `${lineOne}<br>${lineTwo}`)
})
})
describe('delay attributes', function () {
it('uses defaults when no delays specified', function () {
const typingEffectElement = document.createElement('typing-effect')
document.body.append(typingEffectElement)
assert.equal(typingEffectElement.characterDelay, 40)
assert.equal(typingEffectElement.lineDelay, 40)
})
})
})
function once(element, eventName) {
return new Promise(resolve => {
element.addEventListener(eventName, resolve, {once: true})
})
}