@@ -29,7 +29,7 @@ describe('typing-effect', function () {
2929 } )
3030
3131 describe ( 'content typing' , function ( ) {
32- it ( 'types a single line' , function ( done ) {
32+ it ( 'types a single line' , async function ( ) {
3333 const line = 'Welcome to GitHub!'
3434 const container = document . createElement ( 'div' )
3535 container . innerHTML = `
@@ -38,16 +38,16 @@ describe('typing-effect', function () {
3838 <span data-target="typing-effect.cursor">|</span>
3939 </typing-effect>
4040 `
41+ const typingEffectElement = container . querySelector ( 'typing-effect' )
4142 const contentSpan = container . querySelector ( 'span[data-target="typing-effect.content"]' )
4243 document . body . append ( container )
4344
44- setTimeout ( ( ) => {
45- assert . equal ( contentSpan . textContent , line )
46- done ( )
47- } , 1500 )
45+ await once ( typingEffectElement , 'typing:complete' )
46+
47+ assert . equal ( contentSpan . innerHTML , line )
4848 } )
4949
50- it ( 'types multiple lines' , function ( done ) {
50+ it ( 'types multiple lines' , async function ( ) {
5151 const lineOne = 'Welcome!'
5252 const lineTwo = 'Let‘s begin'
5353 const container = document . createElement ( 'div' )
@@ -57,13 +57,29 @@ describe('typing-effect', function () {
5757 <span data-target="typing-effect.cursor">|</span>
5858 </typing-effect>
5959 `
60+ const typingEffectElement = container . querySelector ( 'typing-effect' )
6061 const contentSpan = container . querySelector ( 'span[data-target="typing-effect.content"]' )
6162 document . body . append ( container )
6263
63- setTimeout ( ( ) => {
64- assert . equal ( contentSpan . innerHTML , `${ lineOne } <br>${ lineTwo } ` )
65- done ( )
66- } , 1500 )
64+ await once ( typingEffectElement , 'typing:complete' )
65+
66+ assert . equal ( contentSpan . innerHTML , `${ lineOne } <br>${ lineTwo } ` )
67+ } )
68+ } )
69+
70+ describe ( 'delay attributes' , function ( ) {
71+ it ( 'uses defaults when no delays specified' , function ( ) {
72+ const typingEffectElement = document . createElement ( 'typing-effect' )
73+ document . body . append ( typingEffectElement )
74+
75+ assert . equal ( typingEffectElement . characterDelay , 40 )
76+ assert . equal ( typingEffectElement . lineDelay , 40 )
6777 } )
6878 } )
6979} )
80+
81+ function once ( element , eventName ) {
82+ return new Promise ( resolve => {
83+ element . addEventListener ( eventName , resolve , { once : true } )
84+ } )
85+ }
0 commit comments