@@ -1609,7 +1609,6 @@ describe("pat-inject", function () {
1609
1609
1610
1610
await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1611
1611
1612
- console . log ( document . body . innerHTML ) ;
1613
1612
const modal = document . querySelector ( "#pat-modal" ) ;
1614
1613
expect ( modal ) . toBeTruthy ( ) ;
1615
1614
expect ( modal . innerHTML . replace ( / \s / g, "" ) ) . toBe (
@@ -1644,7 +1643,6 @@ describe("pat-inject", function () {
1644
1643
1645
1644
await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1646
1645
1647
- console . log ( document . body . innerHTML ) ;
1648
1646
const modal = document . querySelector ( "#pat-modal" ) ;
1649
1647
expect ( modal ) . toBeFalsy ( ) ;
1650
1648
} ) ;
@@ -1742,6 +1740,56 @@ describe("pat-inject", function () {
1742
1740
expect ( title . textContent . trim ( ) ) . toBe ( "test" ) ; // Old title
1743
1741
} ) ;
1744
1742
} ) ;
1743
+
1744
+ describe ( "9.5 - support multiple source element matches." , function ( ) {
1745
+ let spy_ajax ;
1746
+
1747
+ beforeEach ( function ( ) {
1748
+ spy_ajax = jest . spyOn ( $ , "ajax" ) . mockImplementation ( ( ) => deferred ) ;
1749
+ } ) ;
1750
+
1751
+ afterEach ( function ( ) {
1752
+ spy_ajax . mockRestore ( ) ;
1753
+ } ) ;
1754
+
1755
+ it ( "9.5.1 - Injects multiple source element matches" , async function ( ) {
1756
+ document . body . innerHTML = `
1757
+ <a class="pat-inject"
1758
+ href="test.html"
1759
+ data-pat-inject="
1760
+ source: a::element;
1761
+ target: .result;
1762
+ ">link</a>
1763
+ <section class="result">
1764
+ </section>
1765
+ ` ;
1766
+
1767
+ answer ( `
1768
+ <html>
1769
+ <body>
1770
+ <a>Link 1</a>
1771
+ <a>Link 2</a>
1772
+ <a>Link 3</a>
1773
+ </body>
1774
+ </html>
1775
+ ` ) ;
1776
+
1777
+ const inject = document . querySelector ( ".pat-inject" ) ;
1778
+
1779
+ pattern . init ( $ ( inject ) ) ;
1780
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1781
+
1782
+ inject . click ( ) ;
1783
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1784
+
1785
+ const injected = document . querySelectorAll ( ".result a" ) ;
1786
+ expect ( injected . length ) . toBe ( 3 ) ;
1787
+ expect ( injected [ 0 ] . textContent ) . toBe ( "Link 1" ) ;
1788
+ expect ( injected [ 1 ] . textContent ) . toBe ( "Link 2" ) ;
1789
+ expect ( injected [ 2 ] . textContent ) . toBe ( "Link 3" ) ;
1790
+ } ) ;
1791
+ } ) ;
1792
+
1745
1793
} ) ;
1746
1794
1747
1795
describe ( "10 - Error handling" , ( ) => {
0 commit comments