@@ -1868,6 +1868,61 @@ describe("pat-inject", function () {
18681868 } ) ;
18691869 } ) ;
18701870
1871+ describe ( "9.6 - injecting tables." , function ( ) {
1872+ let spy_ajax ;
1873+
1874+ beforeEach ( function ( ) {
1875+ spy_ajax = jest . spyOn ( $ , "ajax" ) . mockImplementation ( ( ) => deferred ) ;
1876+ } ) ;
1877+
1878+ afterEach ( function ( ) {
1879+ spy_ajax . mockRestore ( ) ;
1880+ } ) ;
1881+
1882+ it ( "9.6.1 - Correctly injects table rows" , async function ( ) {
1883+ // Table rows <tr> can only be childs of <tbodys> or <thead> elements.
1884+ // If they are childs of <table> elements, the browser implicitly adds a <tbody> element.
1885+ // Table rows cannot be childs of <div> elements or others.
1886+ // There is one exception though - they can be directly added to <template> elements.
1887+ // This test checks this problem which popped up during the 9.10 release cycle and was fixed in:
1888+ // https://github.com/Patternslib/Patterns/pull/1238
1889+
1890+ document . body . innerHTML = `
1891+ <a class="pat-inject"
1892+ href="test.html"
1893+ data-pat-inject="
1894+ source: tr::element;
1895+ target: table;
1896+ ">link</a>
1897+ <table>
1898+ </table>
1899+ ` ;
1900+
1901+ answer ( `
1902+ <html>
1903+ <body>
1904+ <table>
1905+ <tr><td>wohoo</td></tr>
1906+ </table>
1907+ </body>
1908+ </html>
1909+ ` ) ;
1910+
1911+ const inject = document . querySelector ( ".pat-inject" ) ;
1912+
1913+ pattern . init ( $ ( inject ) ) ;
1914+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1915+
1916+ inject . click ( ) ;
1917+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1918+
1919+
1920+ console . log ( document . body . outerHTML ) ;
1921+
1922+ const injected = document . querySelectorAll ( "table tr" ) ;
1923+ expect ( injected . length ) . toBe ( 1 ) ;
1924+ } ) ;
1925+ } ) ;
18711926 } ) ;
18721927
18731928 describe ( "10 - Error handling" , ( ) => {
0 commit comments