@@ -210,20 +210,37 @@ describe("Basepattern class tests", function () {
210
210
expect ( cnt ) . toBe ( 1 ) ;
211
211
} ) ;
212
212
213
- it ( "6.2 - Throws a init event after asynchronous initialization has finished ." , async function ( ) {
213
+ it ( "6.2 - Throws bubbling initialization events ." , async function ( ) {
214
214
const events = ( await import ( "./events" ) ) . default ;
215
215
class Pat extends BasePattern {
216
216
static name = "example" ;
217
217
static trigger = ".example" ;
218
+
219
+ async init ( ) {
220
+ this . el . dispatchEvent ( new Event ( "initializing" ) , { bubbles : true } ) ;
221
+ }
218
222
}
219
223
220
- const el = document . createElement ( "div" ) ;
224
+ document . body . innerHTML = "<div></div>" ;
225
+ const el = document . querySelector ( "div" ) ;
226
+
227
+ const event_list = [ ] ;
228
+ document . body . addEventListener ( "pre-init.example.patterns" , ( ) =>
229
+ event_list . push ( "pre-init.example.patterns" )
230
+ ) ;
231
+ document . body . addEventListener ( "pre-init.example.patterns" , ( ) =>
232
+ event_list . push ( "initializing" )
233
+ ) ;
234
+ document . body . addEventListener ( "pre-init.example.patterns" , ( ) =>
235
+ event_list . push ( "init.example.patterns" )
236
+ ) ;
221
237
222
238
const pat = new Pat ( el ) ;
223
239
await events . await_pattern_init ( pat ) ;
224
240
225
- // If test reaches this expect statement, the init event catched.
226
- expect ( true ) . toBe ( true ) ;
241
+ expect ( event_list [ 0 ] ) . toBe ( "pre-init.example.patterns" ) ;
242
+ expect ( event_list [ 1 ] ) . toBe ( "initializing" ) ;
243
+ expect ( event_list [ 2 ] ) . toBe ( "init.example.patterns" ) ;
227
244
} ) ;
228
245
229
246
it ( "6.3 - Throws a not-init event in case of an double initialization event which is handled by await_pattern_init." , async function ( ) {
0 commit comments