@@ -210,20 +210,37 @@ describe("Basepattern class tests", function () {
210210 expect ( cnt ) . toBe ( 1 ) ;
211211 } ) ;
212212
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 ( ) {
214214 const events = ( await import ( "./events" ) ) . default ;
215215 class Pat extends BasePattern {
216216 static name = "example" ;
217217 static trigger = ".example" ;
218+
219+ async init ( ) {
220+ this . el . dispatchEvent ( new Event ( "initializing" ) , { bubbles : true } ) ;
221+ }
218222 }
219223
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+ ) ;
221237
222238 const pat = new Pat ( el ) ;
223239 await events . await_pattern_init ( pat ) ;
224240
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" ) ;
227244 } ) ;
228245
229246 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