@@ -519,10 +519,8 @@ describe("pat-inject", function () {
519519 } ) ;
520520 } ) ;
521521
522- describe ( "DOM tests" , function ( ) {
523- beforeEach ( function ( ) { } ) ;
524-
525- it ( "The pat-inject-success get triggered after successful injection" , async function ( ) {
522+ describe ( "Injection events tests" , function ( ) {
523+ it ( "triggers the pat-inject-success event after successful injection" , async function ( ) {
526524 const spy_ajax = jest . spyOn ( $ , "ajax" ) . mockImplementation ( ( ) => deferred ) ;
527525 document . body . innerHTML = `
528526 <a class="pat-inject" href="test.html">link</a>
@@ -539,28 +537,42 @@ describe("pat-inject", function () {
539537 spy_ajax . mockRestore ( ) ;
540538 } ) ;
541539
542- describe ( "The patterns-injected event" , function ( ) {
543- it ( "gets triggered after injection has finished'" , async function ( ) {
544- const spy_ajax = jest
545- . spyOn ( $ , "ajax" )
546- . mockImplementation ( ( ) => deferred ) ;
547- var $a = $ ( '<a class="pat-inject" href="test.html#someid">link</a>' ) ;
548- var $div = $ ( '<div id="someid" />' ) ;
549- $ ( "#lab" ) . empty ( ) . append ( $a ) . append ( $div ) ;
550- var callback = jest . fn ( ) ;
551- $ ( document ) . on ( "patterns-injected" , callback ) ;
552- pattern . init ( $a ) ;
553- $a . trigger ( "click" ) ;
554- answer (
555- "<html><body>" + '<div id="someid">repl</div>' + "</body></html>"
556- ) ;
557- await utils . timeout ( 1 ) ; // wait a tick for async to settle.
558- expect ( callback ) . toHaveBeenCalled ( ) ;
540+ it ( "triggers the patterns-injected event after injection has finished'" , async function ( ) {
541+ const spy_ajax = jest . spyOn ( $ , "ajax" ) . mockImplementation ( ( ) => deferred ) ;
542+ var $a = $ ( '<a class="pat-inject" href="test.html#someid">link</a>' ) ;
543+ var $div = $ ( '<div id="someid" />' ) ;
544+ $ ( "#lab" ) . empty ( ) . append ( $a ) . append ( $div ) ;
545+ var callback = jest . fn ( ) ;
546+ $ ( document ) . on ( "patterns-injected" , callback ) ;
547+ pattern . init ( $a ) ;
548+ $a . trigger ( "click" ) ;
549+ answer ( "<html><body>" + '<div id="someid">repl</div>' + "</body></html>" ) ;
550+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
551+ expect ( callback ) . toHaveBeenCalled ( ) ;
559552
560- spy_ajax . mockRestore ( ) ;
561- } ) ;
553+ spy_ajax . mockRestore ( ) ;
562554 } ) ;
563555
556+ it ( "triggers the patterns-injected-scanned event after the injected content has been scanned" , async function ( ) {
557+ const spy_ajax = jest . spyOn ( $ , "ajax" ) . mockImplementation ( ( ) => deferred ) ;
558+ var $a = $ ( '<a class="pat-inject" href="test.html#someid">link</a>' ) ;
559+ var $div = $ ( '<div id="someid" />' ) ;
560+ $ ( "#lab" ) . empty ( ) . append ( $a ) . append ( $div ) ;
561+ var callback = jest . fn ( ) ;
562+ $ ( document ) . on ( "patterns-injected" , callback ) ;
563+ pattern . init ( $a ) ;
564+ $a . trigger ( "click" ) ;
565+ answer ( "<html><body>" + '<div id="someid">repl</div>' + "</body></html>" ) ;
566+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
567+ expect ( callback ) . toHaveBeenCalled ( ) ;
568+
569+ spy_ajax . mockRestore ( ) ;
570+ } ) ;
571+ } ) ;
572+
573+ describe ( "DOM tests" , function ( ) {
574+ beforeEach ( function ( ) { } ) ;
575+
564576 describe ( "Injection on an anchor element" , function ( ) {
565577 var $a , $div ;
566578 let spy_ajax ;
0 commit comments