@@ -29,7 +29,7 @@ describe('typing-effect', function () {
29
29
} )
30
30
31
31
describe ( 'content typing' , function ( ) {
32
- it ( 'types a single line' , function ( done ) {
32
+ it ( 'types a single line' , async function ( ) {
33
33
const line = 'Welcome to GitHub!'
34
34
const container = document . createElement ( 'div' )
35
35
container . innerHTML = `
@@ -38,16 +38,16 @@ describe('typing-effect', function () {
38
38
<span data-target="typing-effect.cursor">|</span>
39
39
</typing-effect>
40
40
`
41
+ const typingEffectElement = container . querySelector ( 'typing-effect' )
41
42
const contentSpan = container . querySelector ( 'span[data-target="typing-effect.content"]' )
42
43
document . body . append ( container )
43
44
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 )
48
48
} )
49
49
50
- it ( 'types multiple lines' , function ( done ) {
50
+ it ( 'types multiple lines' , async function ( ) {
51
51
const lineOne = 'Welcome!'
52
52
const lineTwo = 'Let‘s begin'
53
53
const container = document . createElement ( 'div' )
@@ -57,13 +57,29 @@ describe('typing-effect', function () {
57
57
<span data-target="typing-effect.cursor">|</span>
58
58
</typing-effect>
59
59
`
60
+ const typingEffectElement = container . querySelector ( 'typing-effect' )
60
61
const contentSpan = container . querySelector ( 'span[data-target="typing-effect.content"]' )
61
62
document . body . append ( container )
62
63
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 )
67
77
} )
68
78
} )
69
79
} )
80
+
81
+ function once ( element , eventName ) {
82
+ return new Promise ( resolve => {
83
+ element . addEventListener ( eventName , resolve , { once : true } )
84
+ } )
85
+ }
0 commit comments