@@ -21,7 +21,31 @@ const initSkyNavJS = (utils: PleasantestUtils, navButton: ElementHandle) =>
2121test (
2222 'can be opened on small screens' ,
2323 withBrowser ( { device : iPhone } , async ( { utils, screen, user, page } ) => {
24- await utils . injectHTML ( await skyNavMarkup ( { includeMainDemo : true , menu } ) ) ;
24+ // The rendered markup needs to be captured so we can pass it into the
25+ // `page.evaluate` function below
26+ const renderedMarkup = await skyNavMarkup ( {
27+ includeMainDemo : true ,
28+ menu,
29+ } ) ;
30+ // Pleasantest uses `document.innerHTML` to inject the markup into the DOM,
31+ // but that means inline scripts are not executed.
32+ // @see https://github.com/cloudfour/pleasantest/issues/526
33+ //
34+ // > HTML5 specifies that a <script> tag inserted with innerHTML should not execute.
35+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML#security_considerations
36+ //
37+ // This causes this test to fail because the Sky Nav template has an inline
38+ // script. To get around that, the code below uses `document.write` instead
39+ // which _will_ execute the inline script.
40+ //
41+ // Using `document.write` is discouraged. For the purposes of this test,
42+ // though, it is okay.
43+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Document/write
44+ await page . evaluate ( ( renderedMarkup ) => {
45+ document . body . innerHTML = '' ;
46+ document . write ( renderedMarkup ) ;
47+ } , renderedMarkup ) ;
48+
2549 await loadGlobalCSS ( utils ) ;
2650 const navButton = await screen . getByRole ( 'button' , {
2751 name : / t o g g l e m a i n m e n u / i,
0 commit comments