@@ -1739,6 +1739,84 @@ describe("pat-inject", function () {
1739
1739
expect ( title ) . toBeTruthy ( ) ;
1740
1740
expect ( title . textContent . trim ( ) ) . toBe ( "test" ) ; // Old title
1741
1741
} ) ;
1742
+
1743
+ it ( "9.4.3 - Does not break, if no title is found in source" , async function ( ) {
1744
+ document . head . innerHTML = `
1745
+ <title>test</title>
1746
+ ` ;
1747
+ document . body . innerHTML = `
1748
+ <a class="pat-inject"
1749
+ href="test.html"
1750
+ data-pat-inject="
1751
+ source: body;
1752
+ target: body;
1753
+ history: record;
1754
+ ">link</a>
1755
+ ` ;
1756
+
1757
+ answer ( `
1758
+ <html>
1759
+ <body>
1760
+ OK
1761
+ </body>
1762
+ </html>
1763
+ ` ) ;
1764
+
1765
+ const inject = document . querySelector ( ".pat-inject" ) ;
1766
+
1767
+ pattern . init ( $ ( inject ) ) ;
1768
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1769
+
1770
+ inject . click ( ) ;
1771
+
1772
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1773
+
1774
+ expect ( document . body . textContent . trim ( ) ) . toBe ( "OK" ) ;
1775
+
1776
+ // Title in head target is not modified.
1777
+ const title = document . head . querySelector ( "title" ) ;
1778
+ expect ( title ) . toBeTruthy ( ) ;
1779
+ expect ( title . textContent . trim ( ) ) . toBe ( "test" ) ; // Old title
1780
+ } ) ;
1781
+
1782
+ it ( "9.4.4 - Does not break, if no title is found in target" , async function ( ) {
1783
+ document . head . innerHTML = "" ;
1784
+ document . body . innerHTML = `
1785
+ <a class="pat-inject"
1786
+ href="test.html"
1787
+ data-pat-inject="
1788
+ source: body;
1789
+ target: body;
1790
+ history: record;
1791
+ ">link</a>
1792
+ ` ;
1793
+
1794
+ answer ( `
1795
+ <html>
1796
+ <head>
1797
+ <title>hello</title>
1798
+ <body>
1799
+ OK
1800
+ </body>
1801
+ </html>
1802
+ ` ) ;
1803
+
1804
+ const inject = document . querySelector ( ".pat-inject" ) ;
1805
+
1806
+ pattern . init ( $ ( inject ) ) ;
1807
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1808
+
1809
+ inject . click ( ) ;
1810
+
1811
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1812
+
1813
+ expect ( document . body . textContent . trim ( ) ) . toBe ( "OK" ) ;
1814
+
1815
+ // There is no title to be updated in target.
1816
+ const title = document . head . querySelector ( "title" ) ;
1817
+ expect ( title ) . toBeFalsy ( ) ;
1818
+ } ) ;
1819
+
1742
1820
} ) ;
1743
1821
1744
1822
describe ( "9.5 - support multiple source element matches." , function ( ) {
0 commit comments